Akhil Koduri commited on
Commit
1895e5d
·
verified ·
1 Parent(s): 6315870

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -19
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
- if uploaded_file.type == "text/csv":
49
- # Process CSV file
50
- df = pd.read_csv(uploaded_file)
51
- if 'text' not in df.columns:
52
- st.write("The CSV file must contain a 'text' column.")
53
- else:
54
- df['Prediction'] = df['text'].apply(lambda x: classify_text(x)[0])
55
- df['Confidence'] = df['text'].apply(lambda x: classify_text(x)[1])
56
- st.write(df)
 
57
 
58
- elif uploaded_file.type == "application/pdf":
59
- # Process PDF file
60
- with fitz.open(stream=uploaded_file.read(), filetype="pdf") as doc:
61
- text = ""
62
- for page in doc:
63
- text += page.get_text()
64
 
65
- # Perform classification
66
- label, score = classify_text(text)
67
- st.write(f"**Predicted Class for PDF:** {label}")
68
- st.write(f"**Confidence:** {score:.4f}")
 
 
 
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}")