Jonas
commited on
Commit
·
5565cf6
1
Parent(s):
d14cc09
Change output formatting from markdown to string for event results and update interface to use textboxes for raw data display
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}"
|
|
@@ -53,7 +53,7 @@ def format_serious_outcomes_results(data: dict, drug_name: str) -> str:
|
|
| 53 |
try:
|
| 54 |
df = pd.DataFrame(data["results"])
|
| 55 |
df = df.rename(columns={"term": "Serious Outcome", "count": "Report Count"})
|
| 56 |
-
result_string = df.
|
| 57 |
return header + result_string
|
| 58 |
except Exception as e:
|
| 59 |
return f"An error occurred while formatting the data: {e}"
|
|
@@ -121,12 +121,13 @@ 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 |
-
text_summary = format_serious_outcomes_results(data, drug_name)
|
| 125 |
|
| 126 |
if "error" in data or not data.get("results"):
|
| 127 |
-
|
|
|
|
| 128 |
|
| 129 |
chart = create_outcome_chart(data, drug_name)
|
|
|
|
| 130 |
return chart, text_summary
|
| 131 |
|
| 132 |
def drug_event_stats_tool(drug_name: str, event_name: str):
|
|
@@ -205,7 +206,7 @@ interface1 = gr.Interface(
|
|
| 205 |
],
|
| 206 |
outputs=[
|
| 207 |
gr.Plot(label="Top Adverse Events Chart"),
|
| 208 |
-
gr.
|
| 209 |
],
|
| 210 |
title="Top Adverse Events by Drug",
|
| 211 |
description="Find the most frequently reported adverse events for a specific medication.",
|
|
@@ -222,7 +223,7 @@ interface3 = gr.Interface(
|
|
| 222 |
],
|
| 223 |
outputs=[
|
| 224 |
gr.Plot(label="Top Serious Outcomes Chart"),
|
| 225 |
-
gr.
|
| 226 |
],
|
| 227 |
title="Serious Outcome Analysis",
|
| 228 |
description="Find the most frequently reported serious outcomes (e.g., hospitalization, death) for a specific medication.",
|
|
|
|
| 32 |
try:
|
| 33 |
df = pd.DataFrame(data["results"])
|
| 34 |
df = df.rename(columns={"term": "Adverse Event", "count": "Report Count"})
|
| 35 |
+
result_string = df.to_string(index=False)
|
| 36 |
return header + result_string
|
| 37 |
except Exception as e:
|
| 38 |
return f"An error occurred while formatting the data: {e}"
|
|
|
|
| 53 |
try:
|
| 54 |
df = pd.DataFrame(data["results"])
|
| 55 |
df = df.rename(columns={"term": "Serious Outcome", "count": "Report Count"})
|
| 56 |
+
result_string = df.to_string(index=False)
|
| 57 |
return header + result_string
|
| 58 |
except Exception as e:
|
| 59 |
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
|
| 132 |
|
| 133 |
def drug_event_stats_tool(drug_name: str, event_name: str):
|
|
|
|
| 206 |
],
|
| 207 |
outputs=[
|
| 208 |
gr.Plot(label="Top Adverse Events Chart"),
|
| 209 |
+
gr.Textbox(label="Top Adverse Events (Raw Data)", lines=15)
|
| 210 |
],
|
| 211 |
title="Top Adverse Events by Drug",
|
| 212 |
description="Find the most frequently reported adverse events for a specific medication.",
|
|
|
|
| 223 |
],
|
| 224 |
outputs=[
|
| 225 |
gr.Plot(label="Top Serious Outcomes Chart"),
|
| 226 |
+
gr.Textbox(label="Top Serious Outcomes (Raw Data)", lines=15)
|
| 227 |
],
|
| 228 |
title="Serious Outcome Analysis",
|
| 229 |
description="Find the most frequently reported serious outcomes (e.g., hospitalization, death) for a specific medication.",
|