Prashasst commited on
Commit
c937396
·
verified ·
1 Parent(s): c5b7007

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -22
app.py CHANGED
@@ -320,28 +320,27 @@ Expected JSON format:
320
 
321
  # Gradio interface function
322
  def process_pdf(pdf):
323
- # text = read_pdf(pdf.path) # Extract text from PDF
324
- # output = generate(text) # Generate structured JSON
325
 
326
- # return output
327
- return f"name {pdf.name} and path {pdf.path}"
328
 
329
- # def show_to_UI(pdf):
330
- # # output = process_pdf(pdf) # Call process_pdf to get JSON
331
- # output= {"metadata": {"name": "John Doe", "age": 30}, "lab_tests": [{"test": "Blood Sugar", "value": "120 mg/dL"}]}
332
 
333
- # # Extract metadata
334
- # metadata = output["metadata"]
335
- # labtests = pd.DataFrame(output["lab_tests"])
336
- # # reds = pd.DataFrame(output["reds"])
337
 
338
- # metadata_str = f"**Patient Name:** {metadata['patient_name']}\n\n" \
339
- # f"**Age:** {metadata['age']}\n\n" \
340
- # # f"**Gender:** {metadata['gender']}\n\n" \
341
- # # f"**Lab Name:** {metadata['lab_name']}\n\n" \
342
- # # f"**Report Date:** {metadata['report_date']}"
343
 
344
- # return metadata_str, labtests
345
 
346
  # Define Gradio interface
347
  with gr.Blocks() as demo:
@@ -351,11 +350,11 @@ with gr.Blocks() as demo:
351
  pdf_input = gr.File(label="Upload PDF Report")
352
  submit_btn = gr.Button("Process")
353
 
354
- # metadata_output = gr.Markdown(label="Metadata")
355
- # lab_test_output = gr.Dataframe(label="Lab Test Results")
356
- # output_display = gr.JSON(label="Extracted Report") # Show JSON output
357
- output_display = gr.Text(label="Extracted Report") # Show JSON output
358
 
359
- submit_btn.click(process_pdf, inputs=[pdf_input], outputs=[output_display])
360
 
361
  demo.launch()
 
320
 
321
  # Gradio interface function
322
  def process_pdf(pdf):
323
+ text = read_pdf(pdf) # Extract text from PDF
324
+ output = generate(text) # Generate structured JSON
325
 
326
+ return output
 
327
 
328
+ def show_to_UI(pdf):
329
+ output = process_pdf(pdf) # Call process_pdf to get JSON
330
+ # output= {"metadata": {"name": "John Doe", "age": 30}, "lab_tests": [{"test": "Blood Sugar", "value": "120 mg/dL"}]}
331
 
332
+ # Extract metadata
333
+ metadata = output["metadata"]
334
+ labtests = pd.DataFrame(output["lab_tests"])
335
+ reds = pd.DataFrame(output["reds"])
336
 
337
+ metadata_str = f"**Patient Name:** {metadata['patient_name']}\n\n" \
338
+ f"**Age:** {metadata['age']}\n\n" \
339
+ f"**Gender:** {metadata['gender']}\n\n" \
340
+ f"**Lab Name:** {metadata['lab_name']}\n\n" \
341
+ f"**Report Date:** {metadata['report_date']}"
342
 
343
+ return metadata_str, labtests, reds, output
344
 
345
  # Define Gradio interface
346
  with gr.Blocks() as demo:
 
350
  pdf_input = gr.File(label="Upload PDF Report")
351
  submit_btn = gr.Button("Process")
352
 
353
+ metadata_output = gr.Markdown("**Patient Name: Prashasst...**")
354
+ lab_test_output = gr.Dataframe(label="Lab Test Results")
355
+ reds_output = gr.Dataframe(label="Reds")
356
+ output_JSON = gr.JSON(label="Extracted Report") # Show JSON output
357
 
358
+ submit_btn.click(process_pdf, inputs=[pdf_input], outputs=[metadata_output, lab_test_output, reds_output,output_JSON])
359
 
360
  demo.launch()