Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
ocr = PaddleOCR(use_angle_cls=True, lang='bn') # 'bn' for Bangla support
|
| 9 |
|
| 10 |
def text_extraction(image):
|
| 11 |
if image is None:
|
| 12 |
return "দয়া করে একটি ছবি আপলোড করুন।"
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
results = ocr.ocr(image, cls=True)
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
text = line[1][0] # text is at index 0 in tuple (text, score)
|
| 22 |
-
extracted_texts.append(text)
|
| 23 |
-
|
| 24 |
-
# সব টেক্সট জোড়া লাগানো (space দিয়ে, অথবা \n দিয়ে paragraph style চাইলে change করো)
|
| 25 |
-
full_text = " ".join(extracted_texts)
|
| 26 |
-
|
| 27 |
-
return full_text.strip() if full_text else "ছবিতে কোনো লেখা খুঁজে পাওয়া যায়নি।"
|
| 28 |
|
| 29 |
-
# Gradio ইন্টারফেস তৈরি
|
| 30 |
demo = gr.Interface(
|
| 31 |
fn=text_extraction,
|
| 32 |
-
inputs=gr.Image(type="numpy"),
|
| 33 |
outputs="text",
|
| 34 |
-
title="Education AI OCR
|
| 35 |
-
description="
|
| 36 |
)
|
| 37 |
|
| 38 |
-
# সার্ভার চালু করা (Hugging Face Spaces-এ share=True দরকার নেই, auto handle করে)
|
| 39 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import easyocr
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
+
# Multiple languages load করা (Bangla + English + Hindi + আরও চাইলে add করো)
|
| 6 |
+
# প্রথমবার load slow, পরে fast
|
| 7 |
+
reader = easyocr.Reader(['bn', 'en', 'hi', 'ar', 'fr', 'es'], gpu=False) # gpu=True যদি HF paid GPU থাকে
|
|
|
|
| 8 |
|
| 9 |
def text_extraction(image):
|
| 10 |
if image is None:
|
| 11 |
return "দয়া করে একটি ছবি আপলোড করুন।"
|
| 12 |
|
| 13 |
+
# readtext-এ detail=0 দিয়ে শুধু text, paragraph=True দিয়ে grouped text (better for books)
|
| 14 |
+
results = reader.readtext(image, detail=0, paragraph=True, min_size=10, contrast_ths=0.1, adjust_contrast=0.5)
|
|
|
|
| 15 |
|
| 16 |
+
# results list of strings (paragraph mode-এ)
|
| 17 |
+
full_text = "\n\n".join(results) # paragraph আলাদা করে দেখানো
|
| 18 |
+
return full_text if full_text.strip() else "ছবিতে কোনো লেখা খুঁজে পাওয়া যায়নি।"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
|
|
|
| 20 |
demo = gr.Interface(
|
| 21 |
fn=text_extraction,
|
| 22 |
+
inputs=gr.Image(type="numpy"),
|
| 23 |
outputs="text",
|
| 24 |
+
title="Education AI OCR - Any Language",
|
| 25 |
+
description="যেকোনো ভাষার (Bangla, English, Hindi, Arabic ইত্যাদি) বই/পাতার ছবি আপলোড করুন। Mixed language-ও detect করবে।"
|
| 26 |
)
|
| 27 |
|
|
|
|
| 28 |
demo.launch()
|