Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
-
import json
|
| 4 |
import fitz # PyMuPDF
|
| 5 |
import pytesseract
|
| 6 |
from pdf2image import convert_from_path
|
|
@@ -333,8 +332,26 @@ def show_to_UI(pdf):
|
|
| 333 |
|
| 334 |
# Extract metadata
|
| 335 |
metadata = output["metadata"]
|
| 336 |
-
labtests = pd.DataFrame(output["lab_tests"])
|
| 337 |
-
reds = pd.DataFrame(output["reds"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
|
| 339 |
metadata_str = f"**Patient Name:** {metadata['patient_name']}\n\n" \
|
| 340 |
f"**Age:** {metadata['age']}\n\n" \
|
|
@@ -342,7 +359,9 @@ def show_to_UI(pdf):
|
|
| 342 |
f"**Lab Name:** {metadata['lab_name']}\n\n" \
|
| 343 |
f"**Report Date:** {metadata['report_date']}"
|
| 344 |
|
| 345 |
-
|
|
|
|
|
|
|
| 346 |
|
| 347 |
|
| 348 |
|
|
@@ -356,9 +375,11 @@ with gr.Blocks() as demo:
|
|
| 356 |
submit_btn = gr.Button("Process")
|
| 357 |
|
| 358 |
metadata_output = gr.Markdown("**Patient Name: Prashasst...**")
|
|
|
|
|
|
|
|
|
|
| 359 |
lab_test_output = gr.Dataframe(label="Lab Test Results")
|
| 360 |
-
reds_output = gr.Dataframe(label="Reds")
|
| 361 |
output_JSON = gr.JSON(label="Extracted Report") # Show JSON output
|
| 362 |
|
| 363 |
-
submit_btn.click(show_to_UI, inputs=[pdf_input], outputs=[metadata_output, lab_test_output,
|
| 364 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
import fitz # PyMuPDF
|
| 4 |
import pytesseract
|
| 5 |
from pdf2image import convert_from_path
|
|
|
|
| 332 |
|
| 333 |
# Extract metadata
|
| 334 |
metadata = output["metadata"]
|
| 335 |
+
# labtests = pd.DataFrame(output["lab_tests"])
|
| 336 |
+
# reds = pd.DataFrame(output["reds"])
|
| 337 |
+
|
| 338 |
+
try:
|
| 339 |
+
labtests = pd.DataFrame(output["lab_tests"],)
|
| 340 |
+
except Exception as e:
|
| 341 |
+
print(f"Error creating lab tests DataFrame: {e}")
|
| 342 |
+
labtests = pd.DataFrame() # Return empty DataFrame
|
| 343 |
+
|
| 344 |
+
try:
|
| 345 |
+
highs = pd.DataFrame(output["reds"]["high"],index=True)
|
| 346 |
+
except Exception as e:
|
| 347 |
+
print(f"Error creating highs DataFrame: {e}")
|
| 348 |
+
highs = pd.DataFrame() # Return empty DataFrame
|
| 349 |
+
|
| 350 |
+
try:
|
| 351 |
+
lows = pd.DataFrame(output["reds"]["low"],)
|
| 352 |
+
except Exception as e:
|
| 353 |
+
print(f"Error creating lowss DataFrame: {e}")
|
| 354 |
+
lows = pd.DataFrame() # Return empty DataFrame
|
| 355 |
|
| 356 |
metadata_str = f"**Patient Name:** {metadata['patient_name']}\n\n" \
|
| 357 |
f"**Age:** {metadata['age']}\n\n" \
|
|
|
|
| 359 |
f"**Lab Name:** {metadata['lab_name']}\n\n" \
|
| 360 |
f"**Report Date:** {metadata['report_date']}"
|
| 361 |
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
return metadata_str,highs,lows, labtests,output
|
| 365 |
|
| 366 |
|
| 367 |
|
|
|
|
| 375 |
submit_btn = gr.Button("Process")
|
| 376 |
|
| 377 |
metadata_output = gr.Markdown("**Patient Name: Prashasst...**")
|
| 378 |
+
with gr.Row():
|
| 379 |
+
high_output = gr.Dataframe(label="High Values")
|
| 380 |
+
low_output = gr.Dataframe(label="Low Values")
|
| 381 |
lab_test_output = gr.Dataframe(label="Lab Test Results")
|
|
|
|
| 382 |
output_JSON = gr.JSON(label="Extracted Report") # Show JSON output
|
| 383 |
|
| 384 |
+
submit_btn.click(show_to_UI, inputs=[pdf_input], outputs=[metadata_output, high_output, low_output,lab_test_output, output_JSON])
|
| 385 |
+
demo.launch(debug=True,share=True)
|