Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,9 @@ from reportlab.pdfgen import canvas
|
|
| 8 |
# Load Hugging Face OCR model
|
| 9 |
ocr_model = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
# Function to extract text using Hugging Face OCR model
|
| 12 |
def extract_text(file_path):
|
| 13 |
try:
|
|
@@ -42,12 +45,15 @@ def analyze_blood_test(file):
|
|
| 42 |
if not extracted_text.strip():
|
| 43 |
return "No readable text found in the uploaded file.", None
|
| 44 |
|
| 45 |
-
# Step 2:
|
|
|
|
|
|
|
|
|
|
| 46 |
analysis_report = "π Analysis Results:\n"
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
-
# Step
|
| 51 |
output_pdf = "analysis_report.pdf"
|
| 52 |
create_pdf_report(f"Extracted Text:\n{extracted_text}\n\n{analysis_report}", output_pdf)
|
| 53 |
|
|
|
|
| 8 |
# Load Hugging Face OCR model
|
| 9 |
ocr_model = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
|
| 10 |
|
| 11 |
+
# Load BioGPT or another medical model
|
| 12 |
+
medical_analyzer = pipeline("text-classification", model="microsoft/biogpt")
|
| 13 |
+
|
| 14 |
# Function to extract text using Hugging Face OCR model
|
| 15 |
def extract_text(file_path):
|
| 16 |
try:
|
|
|
|
| 45 |
if not extracted_text.strip():
|
| 46 |
return "No readable text found in the uploaded file.", None
|
| 47 |
|
| 48 |
+
# Step 2: Analyze extracted text using BioGPT
|
| 49 |
+
analysis_results = medical_analyzer(extracted_text)
|
| 50 |
+
|
| 51 |
+
# Step 3: Generate analysis report
|
| 52 |
analysis_report = "π Analysis Results:\n"
|
| 53 |
+
for item in analysis_results:
|
| 54 |
+
analysis_report += f"- {item['label']}: {item['score']:.2f}\n"
|
| 55 |
|
| 56 |
+
# Step 4: Generate PDF report
|
| 57 |
output_pdf = "analysis_report.pdf"
|
| 58 |
create_pdf_report(f"Extracted Text:\n{extracted_text}\n\n{analysis_report}", output_pdf)
|
| 59 |
|