full_ocr / app.py
mohamed12ahmed's picture
Update app.py
4cf1a36 verified
raw
history blame contribute delete
974 Bytes
import gradio as gr
from ocr_processing import process_image
from PIL import Image
from io import BytesIO
# Gradio Frontend
def gradio_interface(image, langs):
if isinstance(langs, str):
langs_list = [lang.strip() for lang in langs.split(',')]
else:
langs_list = ['en'] # default
buffer = BytesIO()
image.save(buffer, format="PNG")
buffer.seek(0)
text = process_image(buffer, langs=langs_list)
return text
iface = gr.Interface(
fn=gradio_interface,
inputs=[
gr.Image(type="pil", label="Upload Image"),
gr.Textbox(label="Languages (comma-separated, e.g., en,ar,fr)", value="en,ar")
],
outputs=gr.Textbox(label="Extracted Text"),
title="OCR Image Scanner (EasyOCR)",
description="Upload an image, it will correct skew & lighting, then extract text from any language supported by EasyOCR."
)
if __name__ == "__main__":
iface.launch(server_name="0.0.0.0", server_port=7860, debug=True)