Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import gradio as gr
|
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
from classifier import classify
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
HFTOKEN = os.environ["HF_TOKEN"]
|
|
@@ -14,7 +15,7 @@ def load_and_analyze_csv(file, text_field, event_model):
|
|
| 14 |
if text_field not in df.columns:
|
| 15 |
raise gr.Error(f"Error: Enter text column'{text_field}' not in CSV file.")
|
| 16 |
|
| 17 |
-
floods, fires, nones = [], [], []
|
| 18 |
for post in df[text_field].to_list():
|
| 19 |
res = classify(post, event_model, HFTOKEN)
|
| 20 |
if res["event"] == 'flood':
|
|
@@ -23,12 +24,14 @@ def load_and_analyze_csv(file, text_field, event_model):
|
|
| 23 |
fires.append(post)
|
| 24 |
else:
|
| 25 |
nones.append(post)
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
fire_related = gr.CheckboxGroup(choices=fires)
|
| 28 |
flood_related = gr.CheckboxGroup(choices=floods)
|
| 29 |
not_related = gr.CheckboxGroup(choices=nones)
|
| 30 |
-
|
| 31 |
-
return flood_related, fire_related, not_related
|
| 32 |
|
| 33 |
def analyze_selected_texts(selections):
|
| 34 |
selected_texts = selections
|
|
@@ -64,9 +67,10 @@ with gr.Blocks() as demo:
|
|
| 64 |
with gr.Column():
|
| 65 |
gr.Markdown("""### None""")
|
| 66 |
none_checkbox_output = gr.CheckboxGroup(label="Select ONLY incorrect classifications", interactive=True)
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
with gr.Tab("Question Answering"):
|
| 72 |
# XXX Add some button disabling here, if the classification process is not completed first XXX
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
from classifier import classify
|
| 7 |
+
from statistics import mean
|
| 8 |
|
| 9 |
|
| 10 |
HFTOKEN = os.environ["HF_TOKEN"]
|
|
|
|
| 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, scores = [], [], [], []
|
| 19 |
for post in df[text_field].to_list():
|
| 20 |
res = classify(post, event_model, HFTOKEN)
|
| 21 |
if res["event"] == 'flood':
|
|
|
|
| 24 |
fires.append(post)
|
| 25 |
else:
|
| 26 |
nones.append(post)
|
| 27 |
+
scores.append(res["score"])
|
| 28 |
+
|
| 29 |
+
model_confidence = round(mean(scores), 5)
|
| 30 |
fire_related = gr.CheckboxGroup(choices=fires)
|
| 31 |
flood_related = gr.CheckboxGroup(choices=floods)
|
| 32 |
not_related = gr.CheckboxGroup(choices=nones)
|
| 33 |
+
|
| 34 |
+
return flood_related, fire_related, not_related, model_confidence
|
| 35 |
|
| 36 |
def analyze_selected_texts(selections):
|
| 37 |
selected_texts = selections
|
|
|
|
| 67 |
with gr.Column():
|
| 68 |
gr.Markdown("""### None""")
|
| 69 |
none_checkbox_output = gr.CheckboxGroup(label="Select ONLY incorrect classifications", interactive=True)
|
| 70 |
+
|
| 71 |
+
model_confidence = gr.Number(label="Model Confidence")
|
| 72 |
+
predict_button.click(load_and_analyze_csv, inputs=[file_input, text_field, event_model],
|
| 73 |
+
outputs=[flood_checkbox_output, fire_checkbox_output, none_checkbox_output, model_confidence])
|
| 74 |
|
| 75 |
with gr.Tab("Question Answering"):
|
| 76 |
# XXX Add some button disabling here, if the classification process is not completed first XXX
|