Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image
|
4 |
-
import pytesseract
|
5 |
import json
|
6 |
from reportlab.lib.pagesizes import letter
|
7 |
from reportlab.pdfgen import canvas
|
@@ -9,6 +8,9 @@ from reportlab.pdfgen import canvas
|
|
9 |
# Load BioGPT model for recommendations
|
10 |
bio_gpt = pipeline("text-generation", model="microsoft/BioGPT")
|
11 |
|
|
|
|
|
|
|
12 |
# Load reference ranges from dataset.json
|
13 |
def load_reference_ranges(file_path="dataset.json"):
|
14 |
with open(file_path, "r") as file:
|
@@ -17,10 +19,11 @@ def load_reference_ranges(file_path="dataset.json"):
|
|
17 |
|
18 |
reference_ranges = load_reference_ranges()
|
19 |
|
20 |
-
# Extract text from uploaded image using OCR
|
21 |
def extract_text_from_image(image_path):
|
22 |
try:
|
23 |
-
|
|
|
24 |
return text
|
25 |
except Exception as e:
|
26 |
return f"Error extracting text: {e}"
|
@@ -108,7 +111,7 @@ interface = gr.Interface(
|
|
108 |
css="""
|
109 |
body {
|
110 |
font-family: 'Arial', sans-serif;
|
111 |
-
background-color: #
|
112 |
}
|
113 |
.gradio-container {
|
114 |
color: #333;
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image
|
|
|
4 |
import json
|
5 |
from reportlab.lib.pagesizes import letter
|
6 |
from reportlab.pdfgen import canvas
|
|
|
8 |
# Load BioGPT model for recommendations
|
9 |
bio_gpt = pipeline("text-generation", model="microsoft/BioGPT")
|
10 |
|
11 |
+
# Load OCR model
|
12 |
+
ocr_model = pipeline("image-to-text", model="microsoft/trocr-base-handwritten")
|
13 |
+
|
14 |
# Load reference ranges from dataset.json
|
15 |
def load_reference_ranges(file_path="dataset.json"):
|
16 |
with open(file_path, "r") as file:
|
|
|
19 |
|
20 |
reference_ranges = load_reference_ranges()
|
21 |
|
22 |
+
# Extract text from uploaded image using Hugging Face OCR
|
23 |
def extract_text_from_image(image_path):
|
24 |
try:
|
25 |
+
image = Image.open(image_path)
|
26 |
+
text = ocr_model(image)[0]["generated_text"]
|
27 |
return text
|
28 |
except Exception as e:
|
29 |
return f"Error extracting text: {e}"
|
|
|
111 |
css="""
|
112 |
body {
|
113 |
font-family: 'Arial', sans-serif;
|
114 |
+
background-color: #000000;
|
115 |
}
|
116 |
.gradio-container {
|
117 |
color: #333;
|