Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,14 +4,15 @@ from PIL import Image
|
|
| 4 |
import json
|
| 5 |
from reportlab.lib.pagesizes import letter
|
| 6 |
from reportlab.pdfgen import canvas
|
|
|
|
| 7 |
import re
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
# Load BioGPT model for recommendations
|
| 10 |
bio_gpt = pipeline("text-generation", model="microsoft/BioGPT")
|
| 11 |
|
| 12 |
-
# Load OCR model
|
| 13 |
-
ocr_model = pipeline("image-to-text", model="microsoft/trocr-base-handwritten")
|
| 14 |
-
|
| 15 |
# Load reference ranges from dataset.json
|
| 16 |
def load_reference_ranges(file_path="dataset.json"):
|
| 17 |
with open(file_path, "r") as file:
|
|
@@ -35,13 +36,14 @@ parameter_mapping = {
|
|
| 35 |
# Add more mappings as needed
|
| 36 |
}
|
| 37 |
|
| 38 |
-
# Extract text from uploaded image using
|
| 39 |
def extract_text_from_image(image_path):
|
| 40 |
try:
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
| 45 |
except Exception as e:
|
| 46 |
return f"Error extracting text: {e}"
|
| 47 |
|
|
@@ -134,7 +136,7 @@ interface = gr.Interface(
|
|
| 134 |
css="""
|
| 135 |
body {
|
| 136 |
font-family: 'Arial', sans-serif;
|
| 137 |
-
background-color: #
|
| 138 |
}
|
| 139 |
.gradio-container {
|
| 140 |
color: #333;
|
|
|
|
| 4 |
import json
|
| 5 |
from reportlab.lib.pagesizes import letter
|
| 6 |
from reportlab.pdfgen import canvas
|
| 7 |
+
import easyocr
|
| 8 |
import re
|
| 9 |
|
| 10 |
+
# Initialize EasyOCR reader
|
| 11 |
+
reader = easyocr.Reader(["en"], gpu=False)
|
| 12 |
+
|
| 13 |
# Load BioGPT model for recommendations
|
| 14 |
bio_gpt = pipeline("text-generation", model="microsoft/BioGPT")
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
# Load reference ranges from dataset.json
|
| 17 |
def load_reference_ranges(file_path="dataset.json"):
|
| 18 |
with open(file_path, "r") as file:
|
|
|
|
| 36 |
# Add more mappings as needed
|
| 37 |
}
|
| 38 |
|
| 39 |
+
# Extract text from uploaded image using EasyOCR
|
| 40 |
def extract_text_from_image(image_path):
|
| 41 |
try:
|
| 42 |
+
# Read text from image
|
| 43 |
+
result = reader.readtext(image_path, detail=0) # Extract only the text
|
| 44 |
+
extracted_text = " ".join(result)
|
| 45 |
+
print("Extracted Text:", extracted_text) # Debugging
|
| 46 |
+
return extracted_text
|
| 47 |
except Exception as e:
|
| 48 |
return f"Error extracting text: {e}"
|
| 49 |
|
|
|
|
| 136 |
css="""
|
| 137 |
body {
|
| 138 |
font-family: 'Arial', sans-serif;
|
| 139 |
+
background-color: #f9f9f9;
|
| 140 |
}
|
| 141 |
.gradio-container {
|
| 142 |
color: #333;
|