Prashasst commited on
Commit
6d2b657
·
verified ·
1 Parent(s): 1b088e7

Update app.py

Browse files

A little fixes

Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -301,18 +301,22 @@ Expected JSON format:
301
 
302
 
303
 
304
- def showdata(lab_tests):
305
- df = pd.DataFrame(lab_tests)
306
- return df
307
 
308
  # Gradio interface function
309
  def process_pdf(pdf):
310
  text = read_pdf(pdf.name) # Extract text from PDF
311
  output = generate(text) # Generate structured JSON
312
 
313
- labtests=pd.DataFrame(output["lab_tests"])
314
- metadata = json_data["metadata"]
315
- reds=pd.DataFrame(output["reds"])
 
 
 
 
 
 
316
 
317
  metadata_str = f"**Patient Name:** {metadata['patient_name']}\n\n" \
318
  f"**Age:** {metadata['age']}\n\n" \
@@ -320,24 +324,19 @@ def process_pdf(pdf):
320
  f"**Lab Name:** {metadata['lab_name']}\n\n" \
321
  f"**Report Date:** {metadata['report_date']}"
322
 
323
- return metadata_str, labtests, output
324
 
325
  # Define Gradio interface
326
  with gr.Blocks() as demo:
327
  gr.Markdown("# Medical Lab Report Processor")
328
-
329
  with gr.Row():
330
  pdf_input = gr.File(label="Upload PDF Report")
331
  submit_btn = gr.Button("Process")
332
-
333
  metadata_output = gr.Markdown(label="Metadata")
334
  lab_test_output = gr.Dataframe(label="Lab Test Results")
335
 
336
- submit_btn.click(process_pdf, inputs=[pdf_input], outputs=[metadata_output, lab_test_output])
337
-
338
- # Add API access but only expose JSON
339
- demo.api(process_pdf, inputs=[gr.File(type="file")], outputs=gr.JSON(), route="/process")
340
-
341
 
342
- # Launch the app
343
- demo.launch()
 
301
 
302
 
303
 
304
+
 
 
305
 
306
  # Gradio interface function
307
  def process_pdf(pdf):
308
  text = read_pdf(pdf.name) # Extract text from PDF
309
  output = generate(text) # Generate structured JSON
310
 
311
+ return output
312
+
313
+ def show_to_UI(pdf):
314
+ output = process_pdf(pdf) # Call process_pdf to get JSON
315
+
316
+ # Extract metadata
317
+ metadata = output["metadata"]
318
+ labtests = pd.DataFrame(output["lab_tests"])
319
+ reds = pd.DataFrame(output["reds"])
320
 
321
  metadata_str = f"**Patient Name:** {metadata['patient_name']}\n\n" \
322
  f"**Age:** {metadata['age']}\n\n" \
 
324
  f"**Lab Name:** {metadata['lab_name']}\n\n" \
325
  f"**Report Date:** {metadata['report_date']}"
326
 
327
+ return metadata_str, labtests # Return only processed data (not JSON)
328
 
329
  # Define Gradio interface
330
  with gr.Blocks() as demo:
331
  gr.Markdown("# Medical Lab Report Processor")
332
+
333
  with gr.Row():
334
  pdf_input = gr.File(label="Upload PDF Report")
335
  submit_btn = gr.Button("Process")
336
+
337
  metadata_output = gr.Markdown(label="Metadata")
338
  lab_test_output = gr.Dataframe(label="Lab Test Results")
339
 
340
+ submit_btn.click(show_to_UI, inputs=[pdf_input], outputs=[metadata_output, lab_test_output])
 
 
 
 
341
 
342
+ demo.launch()