jayebaku commited on
Commit
fef8b06
·
verified ·
1 Parent(s): 47c214e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -9
app.py CHANGED
@@ -1,18 +1,34 @@
 
1
  import time
2
  import gradio as gr
3
  import pandas as pd
4
 
 
5
 
6
- def load_and_analyze_csv(file, text_field):
7
- df = pd.read_csv(file.name)
 
 
 
 
8
 
9
  if text_field not in df.columns:
10
  raise gr.Error(f"Error: Enter text column'{text_field}' not in CSV file.")
11
-
12
- fire_related = gr.CheckboxGroup(choices=df['text'].to_list()[:5])
13
- flood_related = gr.CheckboxGroup(choices=df['text'].to_list()[:7])
14
- not_related = gr.CheckboxGroup(choices=df['text'].to_list())
15
- time.sleep(5)
 
 
 
 
 
 
 
 
 
 
16
  return fire_related, flood_related, not_related
17
 
18
  def analyze_selected_texts(selections):
@@ -33,7 +49,7 @@ with gr.Blocks() as demo:
33
  file_input = gr.File(label="Upload CSV File")
34
 
35
  with gr.Column(scale=6):
36
- text_field = gr.Textbox(label="Text field name", value="text")
37
  event_model = gr.Dropdown(event_models, label="Select classification model")
38
  predict_button = gr.Button("Start Prediction")
39
 
@@ -50,7 +66,8 @@ with gr.Blocks() as demo:
50
  gr.Markdown("""### None""")
51
  none_checkbox_output = gr.CheckboxGroup(label="Select ONLY incorrect classifications")
52
 
53
- predict_button.click(load_and_analyze_csv, inputs=[file_input, text_field], outputs=[fire_checkbox_output, flood_checkbox_output, none_checkbox_output])
 
54
 
55
  with gr.Tab("Question Answering"):
56
  # XXX Add some button disabling here, if the classification process is not completed first XXX
 
1
+ import os
2
  import time
3
  import gradio as gr
4
  import pandas as pd
5
 
6
+ from classifier import classify
7
 
8
+
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.")
17
+
18
+ floods, fires, nones = [], [], []
19
+ for post in df[text_field].to_list():
20
+ res = classify(post, event_model, HFTOKEN)
21
+ if res["event"] == 'flood':
22
+ floods.append(post)
23
+ elif res["event"] == 'fire':
24
+ fires.append(post)
25
+ else:
26
+ nones.append(post)
27
+
28
+ fire_related = gr.CheckboxGroup(choices=fires)
29
+ flood_related = gr.CheckboxGroup(choices=floods)
30
+ not_related = gr.CheckboxGroup(choices=nones)
31
+ # time.sleep(5)
32
  return fire_related, flood_related, not_related
33
 
34
  def analyze_selected_texts(selections):
 
49
  file_input = gr.File(label="Upload CSV File")
50
 
51
  with gr.Column(scale=6):
52
+ text_field = gr.Textbox(label="Text field name", value="tweet_text")
53
  event_model = gr.Dropdown(event_models, label="Select classification model")
54
  predict_button = gr.Button("Start Prediction")
55
 
 
66
  gr.Markdown("""### None""")
67
  none_checkbox_output = gr.CheckboxGroup(label="Select ONLY incorrect classifications")
68
 
69
+ predict_button.click(load_and_analyze_csv, inputs=[file_input, text_field, event_model],
70
+ outputs=[fire_checkbox_output, flood_checkbox_output, none_checkbox_output])
71
 
72
  with gr.Tab("Question Answering"):
73
  # XXX Add some button disabling here, if the classification process is not completed first XXX