Spaces:
Running
Running
Update storylines-app.py
Browse files- storylines-app.py +27 -7
storylines-app.py
CHANGED
@@ -15,8 +15,11 @@ import ast
|
|
15 |
|
16 |
# Load the CSV file
|
17 |
#df = pd.read_csv("emdat2.csv", sep=',', header=0, dtype=str, encoding='utf-8')
|
18 |
-
df = pd.read_csv("https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/ETOHA/storylines/emdat2.csv", sep=',', header=0, dtype=str, encoding='utf-8')
|
19 |
-
df =
|
|
|
|
|
|
|
20 |
|
21 |
# grp=eval(df.iloc[0]["causal graph"])
|
22 |
#
|
@@ -55,7 +58,7 @@ def plot_cgraph(grp):
|
|
55 |
plt.tight_layout()
|
56 |
return plt.gcf()
|
57 |
|
58 |
-
def display_info(selected_row_str, country, year, month, day):
|
59 |
additional_fields = [
|
60 |
"Country", "ISO", "Subregion", "Region", "Location", "Origin",
|
61 |
"Disaster Group", "Disaster Subgroup", "Disaster Type", "Disaster Subtype", "External IDs",
|
@@ -140,7 +143,15 @@ def display_info(selected_row_str, country, year, month, day):
|
|
140 |
likelihood_multi_hazard = row_data.get('likelihood of multi-hazard risks', '')
|
141 |
best_practices = row_data.get('best practices for managing this risk', '')
|
142 |
recommendations = row_data.get('recommendations and supportive measures for recovery', '')
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
grp = ast.literal_eval(causal_graph_caption) if causal_graph_caption else []
|
145 |
causal_graph_plot = plot_cgraph(grp)
|
146 |
|
@@ -243,8 +254,7 @@ def update_row_dropdown(country, year, month, day):
|
|
243 |
|
244 |
|
245 |
def build_interface():
|
246 |
-
with gr.Blocks() as interface:
|
247 |
-
|
248 |
# Add title and description using text elements
|
249 |
gr.Markdown("## From Data to Narratives: AI-Enhanced Disaster and Health Threats Storylines") # Title
|
250 |
gr.Markdown("This Gradio app complements Health Threats and Disaster event data through generative AI techniques, including the use of Retrieval Augmented Generation (RAG) with the [Europe Media Monitoring (EMM)](https://emm.newsbrief.eu/overview.html) service, "
|
@@ -270,6 +280,10 @@ def build_interface():
|
|
270 |
month_dropdown = gr.Dropdown(choices=[""] + [f"{i:02d}" for i in range(1, 13)], label="Select Month")
|
271 |
day_dropdown = gr.Dropdown(choices=[""] + [f"{i:02d}" for i in range(1, 32)], label="Select Day")
|
272 |
row_dropdown = gr.Dropdown(choices=[], label="Select Disaster Event #", interactive=True)
|
|
|
|
|
|
|
|
|
273 |
|
274 |
# Define the additional fields once to use later in both position and function
|
275 |
additional_fields = [
|
@@ -294,6 +308,7 @@ def build_interface():
|
|
294 |
month_dropdown
|
295 |
day_dropdown
|
296 |
row_dropdown
|
|
|
297 |
|
298 |
outputs = [
|
299 |
gr.Textbox(label="Key Information", interactive=False),
|
@@ -340,7 +355,12 @@ def build_interface():
|
|
340 |
# Update the display information when a row is selected
|
341 |
row_dropdown.change(
|
342 |
fn=display_info,
|
343 |
-
inputs=[row_dropdown, country_dropdown, year_dropdown, month_dropdown, day_dropdown],
|
|
|
|
|
|
|
|
|
|
|
344 |
outputs=outputs
|
345 |
)
|
346 |
|
|
|
15 |
|
16 |
# Load the CSV file
|
17 |
#df = pd.read_csv("emdat2.csv", sep=',', header=0, dtype=str, encoding='utf-8')
|
18 |
+
#df = pd.read_csv("https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/ETOHA/storylines/emdat2.csv", sep=',', header=0, dtype=str, encoding='utf-8')
|
19 |
+
#df = pd.read_csv("/eos/jeodpp/home/users/roncmic/data/crisesStorylinesRAG/procem_graph.csv", sep=',', header=0, dtype=str, encoding='utf-8')
|
20 |
+
df = pd.read_csv("https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/ETOHA/storylines/procem_graph.csv", sep=',', header=0, dtype=str, encoding='utf-8')
|
21 |
+
#df = df.drop_duplicates(subset='DisNo.', keep='first') #I drop all duplicates for column "DisNo.", keeping the first occurrence
|
22 |
+
|
23 |
|
24 |
# grp=eval(df.iloc[0]["causal graph"])
|
25 |
#
|
|
|
58 |
plt.tight_layout()
|
59 |
return plt.gcf()
|
60 |
|
61 |
+
def display_info(selected_row_str, country, year, month, day, graph_type):
|
62 |
additional_fields = [
|
63 |
"Country", "ISO", "Subregion", "Region", "Location", "Origin",
|
64 |
"Disaster Group", "Disaster Subgroup", "Disaster Type", "Disaster Subtype", "External IDs",
|
|
|
143 |
likelihood_multi_hazard = row_data.get('likelihood of multi-hazard risks', '')
|
144 |
best_practices = row_data.get('best practices for managing this risk', '')
|
145 |
recommendations = row_data.get('recommendations and supportive measures for recovery', '')
|
146 |
+
if graph_type == "LLaMA Graph":
|
147 |
+
causal_graph_caption = row_data.get('llama graph', '')
|
148 |
+
elif graph_type == "Mixtral Graph":
|
149 |
+
causal_graph_caption = row_data.get('mixtral graph', '')
|
150 |
+
elif graph_type == "Ensemble Graph":
|
151 |
+
causal_graph_caption = row_data.get('ensemble graph', '')
|
152 |
+
else:
|
153 |
+
causal_graph_caption = ''
|
154 |
+
#causal_graph_caption = row_data.get('causal graph', '')
|
155 |
grp = ast.literal_eval(causal_graph_caption) if causal_graph_caption else []
|
156 |
causal_graph_plot = plot_cgraph(grp)
|
157 |
|
|
|
254 |
|
255 |
|
256 |
def build_interface():
|
257 |
+
with gr.Blocks() as interface:
|
|
|
258 |
# Add title and description using text elements
|
259 |
gr.Markdown("## From Data to Narratives: AI-Enhanced Disaster and Health Threats Storylines") # Title
|
260 |
gr.Markdown("This Gradio app complements Health Threats and Disaster event data through generative AI techniques, including the use of Retrieval Augmented Generation (RAG) with the [Europe Media Monitoring (EMM)](https://emm.newsbrief.eu/overview.html) service, "
|
|
|
280 |
month_dropdown = gr.Dropdown(choices=[""] + [f"{i:02d}" for i in range(1, 13)], label="Select Month")
|
281 |
day_dropdown = gr.Dropdown(choices=[""] + [f"{i:02d}" for i in range(1, 32)], label="Select Day")
|
282 |
row_dropdown = gr.Dropdown(choices=[], label="Select Disaster Event #", interactive=True)
|
283 |
+
graph_type_dropdown = gr.Dropdown(
|
284 |
+
choices=["LLaMA Graph", "Mixtral Graph", "Ensemble Graph"],
|
285 |
+
label="Select Graph Type"
|
286 |
+
)
|
287 |
|
288 |
# Define the additional fields once to use later in both position and function
|
289 |
additional_fields = [
|
|
|
308 |
month_dropdown
|
309 |
day_dropdown
|
310 |
row_dropdown
|
311 |
+
graph_type_dropdown
|
312 |
|
313 |
outputs = [
|
314 |
gr.Textbox(label="Key Information", interactive=False),
|
|
|
355 |
# Update the display information when a row is selected
|
356 |
row_dropdown.change(
|
357 |
fn=display_info,
|
358 |
+
inputs=[row_dropdown, country_dropdown, year_dropdown, month_dropdown, day_dropdown, graph_type_dropdown],
|
359 |
+
outputs=outputs
|
360 |
+
)
|
361 |
+
graph_type_dropdown.change(
|
362 |
+
fn=display_info,
|
363 |
+
inputs=[row_dropdown, country_dropdown, year_dropdown, month_dropdown, day_dropdown, graph_type_dropdown],
|
364 |
outputs=outputs
|
365 |
)
|
366 |
|