Update app.py
Browse files
app.py
CHANGED
|
@@ -320,28 +320,27 @@ Expected JSON format:
|
|
| 320 |
|
| 321 |
# Gradio interface function
|
| 322 |
def process_pdf(pdf):
|
| 323 |
-
|
| 324 |
-
|
| 325 |
|
| 326 |
-
|
| 327 |
-
return f"name {pdf.name} and path {pdf.path}"
|
| 328 |
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
#
|
| 332 |
|
| 333 |
-
#
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
|
| 344 |
-
|
| 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 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
|
| 359 |
-
submit_btn.click(process_pdf, inputs=[pdf_input], outputs=[
|
| 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()
|