Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,34 @@
|
|
|
|
1 |
import time
|
2 |
import gradio as gr
|
3 |
import pandas as pd
|
4 |
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
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 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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="
|
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
|
|
|
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
|