Jonas commited on
Commit
8e004b8
·
1 Parent(s): 1013ff5

Enhance report_source_tool in app.py to return error messages and improve output formatting; update Gradio interface to include Markdown output for better user feedback.

Browse files
Files changed (2) hide show
  1. app.py +11 -4
  2. openfda_client.py +1 -1
app.py CHANGED
@@ -161,15 +161,19 @@ def report_source_tool(drug_name: str):
161
  drug_name (str): The generic name of the drug is preferred. A small sample of brand names (e.g., 'Tylenol') are converted to generic names for demonstration purposes.
162
 
163
  Returns:
164
- A Plotly figure.
165
  """
166
  data = get_report_source_data(drug_name)
167
 
 
 
 
168
  if not data or not data.get("results"):
169
- return create_placeholder_chart(f"No report source data found for '{drug_name}'.")
 
170
 
171
  chart = create_pie_chart(data, drug_name)
172
- return chart
173
 
174
  # --- Gradio Interface ---
175
 
@@ -261,7 +265,10 @@ interface5 = gr.Interface(
261
  inputs=[
262
  gr.Textbox(label="Drug Name", info="e.g., 'Aspirin', 'Lisinopril'")
263
  ],
264
- outputs=[gr.Plot(label="Report Source Breakdown")],
 
 
 
265
  title="Report Source Breakdown",
266
  description="Show a pie chart breaking down the source of the reports (e.g., Consumer, Physician).",
267
  examples=[["Lisinopril"], ["Ibuprofen"]],
 
161
  drug_name (str): The generic name of the drug is preferred. A small sample of brand names (e.g., 'Tylenol') are converted to generic names for demonstration purposes.
162
 
163
  Returns:
164
+ A Plotly figure and a string for the Markdown output.
165
  """
166
  data = get_report_source_data(drug_name)
167
 
168
+ if "error" in data:
169
+ return None, f"An error occurred: {data['error']}"
170
+
171
  if not data or not data.get("results"):
172
+ message = f"No report source data found for '{drug_name}'."
173
+ return create_placeholder_chart(message), message
174
 
175
  chart = create_pie_chart(data, drug_name)
176
+ return chart, ""
177
 
178
  # --- Gradio Interface ---
179
 
 
265
  inputs=[
266
  gr.Textbox(label="Drug Name", info="e.g., 'Aspirin', 'Lisinopril'")
267
  ],
268
+ outputs=[
269
+ gr.Plot(label="Report Source Breakdown"),
270
+ gr.Markdown()
271
+ ],
272
  title="Report Source Breakdown",
273
  description="Show a pie chart breaking down the source of the reports (e.g., Consumer, Physician).",
274
  examples=[["Lisinopril"], ["Ibuprofen"]],
openfda_client.py CHANGED
@@ -379,7 +379,7 @@ def get_report_source_data(drug_name: str) -> dict:
379
 
380
  query = (
381
  f'search=patient.drug.medicinalproduct:"{drug_name_processed}"'
382
- f'&count=primarysource.qualification.exact&limit=5'
383
  )
384
 
385
  try:
 
379
 
380
  query = (
381
  f'search=patient.drug.medicinalproduct:"{drug_name_processed}"'
382
+ f'&count=patient.reaction.reactionmeddrapt.exact&limit=5'
383
  )
384
 
385
  try: