Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,29 @@
|
|
| 1 |
-
from flask import Flask, request, jsonify
|
| 2 |
-
from ocr_processing import process_image
|
| 3 |
import gradio as gr
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
# Flask API Endpoint
|
| 8 |
-
@app.route('/upload', methods=['POST'])
|
| 9 |
-
def upload():
|
| 10 |
-
file = request.files['image']
|
| 11 |
-
langs = request.form.get('langs', 'eng+ara')
|
| 12 |
-
text = process_image(file, langs=langs)
|
| 13 |
-
return jsonify({"text": text})
|
| 14 |
|
| 15 |
# Gradio Frontend
|
| 16 |
def gradio_interface(image, langs):
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
buffer = BytesIO()
|
| 19 |
image.save(buffer, format="PNG")
|
| 20 |
buffer.seek(0)
|
| 21 |
-
text = process_image(buffer, langs)
|
| 22 |
return text
|
| 23 |
|
| 24 |
iface = gr.Interface(
|
| 25 |
fn=gradio_interface,
|
| 26 |
inputs=[
|
| 27 |
gr.Image(type="pil", label="Upload Image"),
|
| 28 |
-
gr.Textbox(label="Languages (
|
| 29 |
],
|
| 30 |
outputs=gr.Textbox(label="Extracted Text"),
|
| 31 |
-
title="OCR Image Scanner",
|
| 32 |
-
description="Upload an image, it will correct skew & lighting, then extract text
|
| 33 |
)
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from ocr_processing import process_image
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from io import BytesIO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Gradio Frontend
|
| 7 |
def gradio_interface(image, langs):
|
| 8 |
+
if isinstance(langs, str):
|
| 9 |
+
langs_list = [lang.strip() for lang in langs.split(',')]
|
| 10 |
+
else:
|
| 11 |
+
langs_list = ['en'] # default
|
| 12 |
buffer = BytesIO()
|
| 13 |
image.save(buffer, format="PNG")
|
| 14 |
buffer.seek(0)
|
| 15 |
+
text = process_image(buffer, langs=langs_list)
|
| 16 |
return text
|
| 17 |
|
| 18 |
iface = gr.Interface(
|
| 19 |
fn=gradio_interface,
|
| 20 |
inputs=[
|
| 21 |
gr.Image(type="pil", label="Upload Image"),
|
| 22 |
+
gr.Textbox(label="Languages (comma-separated, e.g., en,ar,fr)", value="en,ar")
|
| 23 |
],
|
| 24 |
outputs=gr.Textbox(label="Extracted Text"),
|
| 25 |
+
title="OCR Image Scanner (EasyOCR)",
|
| 26 |
+
description="Upload an image, it will correct skew & lighting, then extract text from any language supported by EasyOCR."
|
| 27 |
)
|
| 28 |
|
| 29 |
if __name__ == "__main__":
|