Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -26,9 +26,9 @@ import os
|
|
26 |
# Function to perform OCR
|
27 |
def ocr(input_file, lang='fas'): # 'fas': Persian language (Farsi)
|
28 |
extracted_text = ""
|
29 |
-
if isinstance(input_file, Image.Image): # If the input is an image
|
30 |
-
|
31 |
-
|
32 |
|
33 |
return extracted_text
|
34 |
|
@@ -82,9 +82,16 @@ def ocr_with_easy(img):
|
|
82 |
Generate OCR
|
83 |
"""
|
84 |
|
85 |
-
def process(input_type,
|
86 |
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
image = file
|
89 |
extracted_text = ocr(image, lang)
|
90 |
return extracted_text
|
|
|
26 |
# Function to perform OCR
|
27 |
def ocr(input_file, lang='fas'): # 'fas': Persian language (Farsi)
|
28 |
extracted_text = ""
|
29 |
+
# if isinstance(input_file, Image.Image): # If the input is an image
|
30 |
+
text = pytesseract.image_to_string(input_file, lang=lang)
|
31 |
+
extracted_text = text
|
32 |
|
33 |
return extracted_text
|
34 |
|
|
|
82 |
Generate OCR
|
83 |
"""
|
84 |
|
85 |
+
def process(input_type, gr_img, lang):
|
86 |
|
87 |
+
if isinstance(gr_img, np.ndarray):
|
88 |
+
# Create a temporary file to save the image
|
89 |
+
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp_file:
|
90 |
+
temp_path = temp_file.name
|
91 |
+
# Save the NumPy array as an image file
|
92 |
+
Image.fromarray(gr_img).save(temp_path)
|
93 |
+
|
94 |
+
image = Image.open(temp_path)
|
95 |
image = file
|
96 |
extracted_text = ocr(image, lang)
|
97 |
return extracted_text
|