ZennyKenny commited on
Commit
1f0cb35
Β·
verified Β·
1 Parent(s): 848f580

gracefully handle CSV

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -38,7 +38,7 @@ def classify_comments():
38
 
39
  # Gradio Interface
40
  with gr.Blocks() as nps:
41
- uploaded_file = gr.File(label="Upload CSV", file_types=["csv"])
42
  template_btn = gr.Button("Use Template")
43
  gr.Markdown("# NPS Comment Categorization")
44
  classify_btn = gr.Button("Classify Comments")
@@ -49,7 +49,8 @@ with gr.Blocks() as nps:
49
  file.seek(0) # Reset file pointer
50
  import io
51
  if file.name.endswith('.csv'):
52
- content = file.read().decode('utf-8')
 
53
  custom_df = pd.read_csv(io.StringIO(content))
54
  else:
55
  return "Error: Uploaded file is not a CSV."
 
38
 
39
  # Gradio Interface
40
  with gr.Blocks() as nps:
41
+ uploaded_file = gr.File(label="Upload CSV", type="file")
42
  template_btn = gr.Button("Use Template")
43
  gr.Markdown("# NPS Comment Categorization")
44
  classify_btn = gr.Button("Classify Comments")
 
49
  file.seek(0) # Reset file pointer
50
  import io
51
  if file.name.endswith('.csv'):
52
+ file.seek(0) # Reset file pointer
53
+ custom_df = pd.read_csv(file)
54
  custom_df = pd.read_csv(io.StringIO(content))
55
  else:
56
  return "Error: Uploaded file is not a CSV."