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

file validation

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -47,7 +47,12 @@ with gr.Blocks() as nps:
47
  def load_data(file):
48
  if file is not None:
49
  file.seek(0) # Reset file pointer
50
- custom_df = pd.read_csv(file)
 
 
 
 
 
51
  if 'customer_comment' not in custom_df.columns:
52
  return "Error: Uploaded CSV must contain a column named 'customer_comment'"
53
  global df
 
47
  def load_data(file):
48
  if file is not None:
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."
56
  if 'customer_comment' not in custom_df.columns:
57
  return "Error: Uploaded CSV must contain a column named 'customer_comment'"
58
  global df