Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,29 +3,29 @@ import pytesseract
|
|
| 3 |
import cv2
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
def process(
|
| 7 |
results = []
|
| 8 |
-
for
|
| 9 |
try:
|
| 10 |
-
img = cv2.imread(
|
| 11 |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
| 12 |
_, threshold_img = cv2.threshold(gray, 127, 255, cv2.THRESH_TOZERO)
|
| 13 |
result = pytesseract.image_to_string(threshold_img, lang=lang)
|
| 14 |
results.append(result)
|
| 15 |
except Exception as e:
|
| 16 |
-
results.append(f"Error processing {
|
| 17 |
finally:
|
| 18 |
-
os.remove(
|
| 19 |
return "\n\n".join(results)
|
| 20 |
|
| 21 |
-
# Get
|
| 22 |
langs = pytesseract.get_languages()
|
| 23 |
|
| 24 |
-
# Define the Gradio interface
|
| 25 |
interface = gr.Interface(
|
| 26 |
fn=process,
|
| 27 |
inputs=[
|
| 28 |
-
gr.
|
| 29 |
gr.Dropdown(label="Select Language", choices=langs, type="value")
|
| 30 |
],
|
| 31 |
outputs="text",
|
|
|
|
| 3 |
import cv2
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
def process(files, lang: str = 'eng') -> str:
|
| 7 |
results = []
|
| 8 |
+
for file in files:
|
| 9 |
try:
|
| 10 |
+
img = cv2.imread(file)
|
| 11 |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
| 12 |
_, threshold_img = cv2.threshold(gray, 127, 255, cv2.THRESH_TOZERO)
|
| 13 |
result = pytesseract.image_to_string(threshold_img, lang=lang)
|
| 14 |
results.append(result)
|
| 15 |
except Exception as e:
|
| 16 |
+
results.append(f"Error processing {file}: {str(e)}")
|
| 17 |
finally:
|
| 18 |
+
os.remove(file)
|
| 19 |
return "\n\n".join(results)
|
| 20 |
|
| 21 |
+
# Get available languages for pytesseract
|
| 22 |
langs = pytesseract.get_languages()
|
| 23 |
|
| 24 |
+
# Define the Gradio interface using gr.Files to allow multiple file uploads
|
| 25 |
interface = gr.Interface(
|
| 26 |
fn=process,
|
| 27 |
inputs=[
|
| 28 |
+
gr.Files(label="Upload Images", file_count="multiple", type="filepath"),
|
| 29 |
gr.Dropdown(label="Select Language", choices=langs, type="value")
|
| 30 |
],
|
| 31 |
outputs="text",
|