jayebaku commited on
Commit
aeada86
·
verified ·
1 Parent(s): 410e6af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -9,8 +9,11 @@ from statistics import mean
9
 
10
  HFTOKEN = os.environ["HF_TOKEN"]
11
 
12
- def load_and_analyze_csv(file, text_field, event_model):
13
- df = pd.read_table(file.name)
 
 
 
14
 
15
  if text_field not in df.columns:
16
  raise gr.Error(f"Error: Enter text column'{text_field}' not in CSV file.")
@@ -91,7 +94,7 @@ with gr.Blocks() as demo:
91
  # T4.5 Relevance Classifier Demo
92
  This is a demo created to explore floods and wildfire classification in social media posts.\n
93
  Usage:\n
94
- -Upload .tsv data file (must contain a text column with social media posts).\n
95
  -Next, type the name of the text column.\n
96
  -Then, choose a BERT classifier model from the drop down.\n
97
  -Finally, click the 'start prediction' buttton.\n
@@ -102,7 +105,7 @@ with gr.Blocks() as demo:
102
  """)
103
  with gr.Row(equal_height=True):
104
  with gr.Column(scale=4):
105
- file_input = gr.File(label="Upload CSV File")
106
 
107
  with gr.Column(scale=6):
108
  text_field = gr.Textbox(label="Text field name", value="tweet_text")
@@ -150,7 +153,7 @@ with gr.Blocks() as demo:
150
  data_eval = gr.DataFrame(visible=False)
151
 
152
  predict_button.click(
153
- load_and_analyze_csv,
154
  inputs=[file_input, text_field, event_model],
155
  outputs=[flood_checkbox_output, fire_checkbox_output, none_checkbox_output, model_confidence, num_posts, data])
156
  accuracy_button.click(
 
9
 
10
  HFTOKEN = os.environ["HF_TOKEN"]
11
 
12
+ def load_and_classify_csv(file, text_field, event_model):
13
+ if ".csv" in file.name:
14
+ df = pd.read_csv(file.name)
15
+ else ".tsv" in file.name:
16
+ df = pd.read_table(file.name)
17
 
18
  if text_field not in df.columns:
19
  raise gr.Error(f"Error: Enter text column'{text_field}' not in CSV file.")
 
94
  # T4.5 Relevance Classifier Demo
95
  This is a demo created to explore floods and wildfire classification in social media posts.\n
96
  Usage:\n
97
+ (1.) Upload .tsv data file (must contain a text column with social media posts).\n
98
  -Next, type the name of the text column.\n
99
  -Then, choose a BERT classifier model from the drop down.\n
100
  -Finally, click the 'start prediction' buttton.\n
 
105
  """)
106
  with gr.Row(equal_height=True):
107
  with gr.Column(scale=4):
108
+ file_input = gr.File(label="Upload CSV or TSV File", file_types=['.tsv', '.csv'])
109
 
110
  with gr.Column(scale=6):
111
  text_field = gr.Textbox(label="Text field name", value="tweet_text")
 
153
  data_eval = gr.DataFrame(visible=False)
154
 
155
  predict_button.click(
156
+ load_and_classify_csv,
157
  inputs=[file_input, text_field, event_model],
158
  outputs=[flood_checkbox_output, fire_checkbox_output, none_checkbox_output, model_confidence, num_posts, data])
159
  accuracy_button.click(