Spaces:
Runtime error
Runtime error
add map vis
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
|
| 3 |
import pandas as pd
|
| 4 |
import util
|
|
|
|
| 5 |
|
| 6 |
# Model names (replace with your actual Hugging Face repo names)
|
| 7 |
MODEL_NAMES = {
|
|
@@ -28,15 +29,6 @@ def extract_entities(model_choice, text):
|
|
| 28 |
|
| 29 |
if not entities:
|
| 30 |
return pd.DataFrame(columns=["outbreak", "cases", "deaths", "date", "location", "latitude", "longtitude"])
|
| 31 |
-
|
| 32 |
-
# Format results into DataFrame
|
| 33 |
-
data = [{
|
| 34 |
-
"Entity": ent["word"],
|
| 35 |
-
"Label": ent["entity_group"],
|
| 36 |
-
"Score": f"{ent['score']:.2f}",
|
| 37 |
-
"Start": ent["start"],
|
| 38 |
-
"End": ent["end"]
|
| 39 |
-
} for ent in entities]
|
| 40 |
|
| 41 |
data = {}
|
| 42 |
for ent in entities:
|
|
@@ -52,9 +44,27 @@ def extract_entities(model_choice, text):
|
|
| 52 |
location_info = util.get_location(ent['word'])
|
| 53 |
data['location'] = location_info['name']
|
| 54 |
data['latitude'] = location_info['latitude']
|
| 55 |
-
data['longtitude'] = location_info['longitude']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
return pd.DataFrame([data])
|
| 58 |
|
| 59 |
# Sample example texts for testing
|
| 60 |
examples = [
|
|
@@ -71,17 +81,17 @@ with gr.Blocks() as demo:
|
|
| 71 |
with gr.Row():
|
| 72 |
model_dropdown = gr.Dropdown(choices=list(MODEL_NAMES.keys()), label="Select Model", value="BioBERT")
|
| 73 |
text_input = gr.Textbox(label="Input Text", placeholder="Enter your sentence here...", lines=4)
|
| 74 |
-
|
| 75 |
-
output_table = gr.Dataframe(headers=["outbreak", "cases", "deaths", "date", "location", "latitude", "longtitude"], interactive=False)
|
| 76 |
-
|
| 77 |
-
run_button = gr.Button("Extract Entities")
|
| 78 |
-
|
| 79 |
-
run_button.click(fn=extract_entities, inputs=[model_dropdown, text_input], outputs=output_table)
|
| 80 |
-
|
| 81 |
gr.Examples(
|
| 82 |
examples=examples,
|
| 83 |
inputs=[text_input],
|
| 84 |
label="Try Examples",
|
| 85 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
demo.launch()
|
|
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
|
| 3 |
import pandas as pd
|
| 4 |
import util
|
| 5 |
+
import folium
|
| 6 |
|
| 7 |
# Model names (replace with your actual Hugging Face repo names)
|
| 8 |
MODEL_NAMES = {
|
|
|
|
| 29 |
|
| 30 |
if not entities:
|
| 31 |
return pd.DataFrame(columns=["outbreak", "cases", "deaths", "date", "location", "latitude", "longtitude"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
data = {}
|
| 34 |
for ent in entities:
|
|
|
|
| 44 |
location_info = util.get_location(ent['word'])
|
| 45 |
data['location'] = location_info['name']
|
| 46 |
data['latitude'] = location_info['latitude']
|
| 47 |
+
data['longtitude'] = location_info['longitude']
|
| 48 |
+
|
| 49 |
+
m = None
|
| 50 |
+
if 'latitude' in data:
|
| 51 |
+
m = folium.Map(location=[data['latitude'], data['longtitude']])
|
| 52 |
+
info = f"""
|
| 53 |
+
<h3>Outbreak Information</h3>
|
| 54 |
+
<strong>Location:</strong> {data.get('location', 'N/A')}<br>
|
| 55 |
+
<strong>Outbreak:</strong> {data.get('outbreak', 'N/A')}<br>
|
| 56 |
+
<strong>Cases:</strong> {data.get('cases', 'N/A')}<br>
|
| 57 |
+
<strong>Deaths:</strong> {data.get('deaths', 'N/A')}<br>
|
| 58 |
+
<strong>Date:</strong> {data.get('date', 'N/A')}<br>
|
| 59 |
+
<strong>Location:</strong> {data.get('location', 'N/A')}
|
| 60 |
+
"""
|
| 61 |
+
folium.Marker(
|
| 62 |
+
location=[data['latitude'], data['longtitude']],
|
| 63 |
+
popup=info,
|
| 64 |
+
icon=folium.Icon(icon="warning", color="red"),
|
| 65 |
+
).add_to(m)
|
| 66 |
|
| 67 |
+
return pd.DataFrame([data]), m._repr_html_()
|
| 68 |
|
| 69 |
# Sample example texts for testing
|
| 70 |
examples = [
|
|
|
|
| 81 |
with gr.Row():
|
| 82 |
model_dropdown = gr.Dropdown(choices=list(MODEL_NAMES.keys()), label="Select Model", value="BioBERT")
|
| 83 |
text_input = gr.Textbox(label="Input Text", placeholder="Enter your sentence here...", lines=4)
|
| 84 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
gr.Examples(
|
| 86 |
examples=examples,
|
| 87 |
inputs=[text_input],
|
| 88 |
label="Try Examples",
|
| 89 |
)
|
| 90 |
+
|
| 91 |
+
run_button = gr.Button("Extract Entities")
|
| 92 |
+
output_table = gr.Dataframe(headers=["outbreak", "cases", "deaths", "date", "location", "latitude", "longtitude"], interactive=False)
|
| 93 |
+
output_map = gr.HTML(label="Map")
|
| 94 |
+
|
| 95 |
+
run_button.click(fn=extract_entities, inputs=[model_dropdown, text_input], outputs=[output_table, output_map])
|
| 96 |
|
| 97 |
demo.launch()
|