Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,38 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import easyocr
|
| 3 |
-
from
|
| 4 |
|
| 5 |
-
|
| 6 |
-
reader = easyocr.Reader(['hi', 'en']) # You can change 'hi' to 'mr' or 'ne' etc.
|
| 7 |
-
translator = Translator()
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
inputs=[
|
| 20 |
gr.Image(type="filepath", label="Upload Image"),
|
| 21 |
-
gr.Dropdown(
|
| 22 |
-
["en", "hi", "mr", "ne", "fr", "de", "es", "bn", "gu", "ta", "te"],
|
| 23 |
-
label="Translate To",
|
| 24 |
-
value="hi"
|
| 25 |
-
)
|
| 26 |
],
|
| 27 |
outputs="text",
|
| 28 |
title="Image Text Translator",
|
| 29 |
-
description="Upload an image with text
|
| 30 |
)
|
| 31 |
|
| 32 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import easyocr
|
| 3 |
+
from deep_translator import GoogleTranslator
|
| 4 |
|
| 5 |
+
reader = easyocr.Reader(['en', 'hi']) # Hindi aur English OCR ke liye
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def extract_and_translate(image, target_lang):
|
| 8 |
+
result = reader.readtext(image, detail=0)
|
| 9 |
+
text = ' '.join(result)
|
| 10 |
+
try:
|
| 11 |
+
translated_text = GoogleTranslator(source='auto', target=target_lang).translate(text)
|
| 12 |
+
except Exception as e:
|
| 13 |
+
translated_text = f"Translation Error: {str(e)}"
|
| 14 |
+
return translated_text
|
| 15 |
|
| 16 |
+
lang_choices = {
|
| 17 |
+
"Hindi": "hi",
|
| 18 |
+
"English": "en",
|
| 19 |
+
"Punjabi": "pa",
|
| 20 |
+
"Gujarati": "gu",
|
| 21 |
+
"Bengali": "bn",
|
| 22 |
+
"Tamil": "ta",
|
| 23 |
+
"Telugu": "te",
|
| 24 |
+
"Marathi": "mr"
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
iface = gr.Interface(
|
| 28 |
+
fn=extract_and_translate,
|
| 29 |
inputs=[
|
| 30 |
gr.Image(type="filepath", label="Upload Image"),
|
| 31 |
+
gr.Dropdown(choices=list(lang_choices.values()), label="Translate To")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
],
|
| 33 |
outputs="text",
|
| 34 |
title="Image Text Translator",
|
| 35 |
+
description="Upload an image with printed text. Extracts and translates text into selected language."
|
| 36 |
)
|
| 37 |
|
| 38 |
+
iface.launch()
|