Jonas
commited on
Commit
·
4adf18d
1
Parent(s):
e8c0366
Update formatting in app.py to display results as HTML tables and handle errors in serious outcomes tool
Browse files
app.py
CHANGED
|
@@ -32,7 +32,7 @@ def format_top_events_results(data: dict, drug_name: str) -> str:
|
|
| 32 |
try:
|
| 33 |
df = pd.DataFrame(data["results"])
|
| 34 |
df = df.rename(columns={"term": "Adverse Event", "count": "Report Count"})
|
| 35 |
-
result_string = df.
|
| 36 |
return header + result_string
|
| 37 |
except Exception as e:
|
| 38 |
return f"An error occurred while formatting the data: {e}"
|
|
@@ -121,6 +121,11 @@ def serious_outcomes_tool(drug_name: str):
|
|
| 121 |
tuple: A Plotly figure and a formatted string with the top serious outcomes.
|
| 122 |
"""
|
| 123 |
data = get_serious_outcomes(drug_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
chart = create_outcome_chart(data, drug_name)
|
| 125 |
text_summary = format_serious_outcomes_results(data, drug_name)
|
| 126 |
return chart, text_summary
|
|
@@ -223,6 +228,7 @@ interface3 = gr.Interface(
|
|
| 223 |
title="Serious Outcome Analysis",
|
| 224 |
description="Find the most frequently reported serious outcomes (e.g., hospitalization, death) for a specific medication.",
|
| 225 |
examples=[["Lisinopril"], ["Ozempic"], ["Metformin"]],
|
|
|
|
| 226 |
)
|
| 227 |
|
| 228 |
interface2 = gr.Interface(
|
|
|
|
| 32 |
try:
|
| 33 |
df = pd.DataFrame(data["results"])
|
| 34 |
df = df.rename(columns={"term": "Adverse Event", "count": "Report Count"})
|
| 35 |
+
result_string = df.to_html(index=False, classes='table table-striped')
|
| 36 |
return header + result_string
|
| 37 |
except Exception as e:
|
| 38 |
return f"An error occurred while formatting the data: {e}"
|
|
|
|
| 121 |
tuple: A Plotly figure and a formatted string with the top serious outcomes.
|
| 122 |
"""
|
| 123 |
data = get_serious_outcomes(drug_name)
|
| 124 |
+
|
| 125 |
+
if "error" in data or not data.get("results"):
|
| 126 |
+
text_summary = format_serious_outcomes_results(data, drug_name)
|
| 127 |
+
return text_summary, text_summary
|
| 128 |
+
|
| 129 |
chart = create_outcome_chart(data, drug_name)
|
| 130 |
text_summary = format_serious_outcomes_results(data, drug_name)
|
| 131 |
return chart, text_summary
|
|
|
|
| 228 |
title="Serious Outcome Analysis",
|
| 229 |
description="Find the most frequently reported serious outcomes (e.g., hospitalization, death) for a specific medication.",
|
| 230 |
examples=[["Lisinopril"], ["Ozempic"], ["Metformin"]],
|
| 231 |
+
allow_flagging="never"
|
| 232 |
)
|
| 233 |
|
| 234 |
interface2 = gr.Interface(
|