Spaces:
Sleeping
Sleeping
Akhil Koduri
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -45,24 +45,27 @@ st.write("Upload a file for classification:")
|
|
45 |
uploaded_file = st.file_uploader("Choose a file", type=["csv", "pdf"])
|
46 |
|
47 |
if uploaded_file is not None:
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
45 |
uploaded_file = st.file_uploader("Choose a file", type=["csv", "pdf"])
|
46 |
|
47 |
if uploaded_file is not None:
|
48 |
+
try:
|
49 |
+
if uploaded_file.type == "text/csv":
|
50 |
+
# Process CSV file
|
51 |
+
df = pd.read_csv(uploaded_file, encoding='utf-8')
|
52 |
+
if 'text' not in df.columns:
|
53 |
+
st.write("The CSV file must contain a 'text' column.")
|
54 |
+
else:
|
55 |
+
df['Prediction'] = df['text'].apply(lambda x: classify_text(x)[0])
|
56 |
+
df['Confidence'] = df['text'].apply(lambda x: classify_text(x)[1])
|
57 |
+
st.write(df)
|
58 |
|
59 |
+
elif uploaded_file.type == "application/pdf":
|
60 |
+
# Process PDF file
|
61 |
+
with fitz.open(stream=uploaded_file.read(), filetype="pdf") as doc:
|
62 |
+
text = ""
|
63 |
+
for page in doc:
|
64 |
+
text += page.get_text()
|
65 |
|
66 |
+
# Perform classification
|
67 |
+
label, score = classify_text(text)
|
68 |
+
st.write(f"**Predicted Class for PDF:** {label}")
|
69 |
+
st.write(f"**Confidence:** {score:.4f}")
|
70 |
+
except Exception as e:
|
71 |
+
st.error(f"Error: {e}")
|