Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,7 @@
|
|
|
|
|
|
|
|
|
|
1 |
# Default reference ranges for common blood components
|
2 |
DEFAULT_RANGES = {
|
3 |
"White Blood Cell Count": (4, 11),
|
@@ -71,3 +75,36 @@ def clean_and_parse_extracted_text(raw_text):
|
|
71 |
df["Component"] = df["Component"].str.replace("Sir 2.0", "", regex=False).str.strip()
|
72 |
|
73 |
return df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
import pandas as pd
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
# Default reference ranges for common blood components
|
6 |
DEFAULT_RANGES = {
|
7 |
"White Blood Cell Count": (4, 11),
|
|
|
75 |
df["Component"] = df["Component"].str.replace("Sir 2.0", "", regex=False).str.strip()
|
76 |
|
77 |
return df
|
78 |
+
|
79 |
+
def process_blood_test(image):
|
80 |
+
"""
|
81 |
+
Process the uploaded blood test report and return the analyzed data.
|
82 |
+
"""
|
83 |
+
# Step 1: Extract text from the image
|
84 |
+
import pytesseract
|
85 |
+
raw_text = pytesseract.image_to_string(image)
|
86 |
+
|
87 |
+
# Step 2: Parse and analyze the extracted text
|
88 |
+
df = clean_and_parse_extracted_text(raw_text)
|
89 |
+
|
90 |
+
# Step 3: Convert the DataFrame to a readable format
|
91 |
+
return df
|
92 |
+
|
93 |
+
# Gradio Interface
|
94 |
+
def analyze_blood_report(image):
|
95 |
+
"""
|
96 |
+
Analyze the blood test report and return a table with results.
|
97 |
+
"""
|
98 |
+
df = process_blood_test(image)
|
99 |
+
return df
|
100 |
+
|
101 |
+
interface = gr.Interface(
|
102 |
+
fn=analyze_blood_report,
|
103 |
+
inputs=gr.Image(type="pil"),
|
104 |
+
outputs=gr.DataFrame(label="Blood Test Analysis"),
|
105 |
+
title="Blood Test Analyzer",
|
106 |
+
description="Upload an image of your blood test report to analyze the values and flag abnormalities.",
|
107 |
+
)
|
108 |
+
|
109 |
+
if __name__ == "__main__":
|
110 |
+
interface.launch()
|