Update app.py
Browse files
app.py
CHANGED
|
@@ -40,12 +40,12 @@ import streamlit as st
|
|
| 40 |
import easyocr
|
| 41 |
from PIL import Image
|
| 42 |
import numpy as np
|
| 43 |
-
import
|
| 44 |
|
| 45 |
# Initialize EasyOCR Reader
|
| 46 |
-
reader = easyocr.Reader(['en'])
|
| 47 |
|
| 48 |
-
st.title("Image to Text Extraction and Translation Using EasyOCR and Translation
|
| 49 |
|
| 50 |
# File uploader for images
|
| 51 |
uploaded_file = st.file_uploader("Choose an image... (JPEG, PNG)", type=["jpg", "jpeg", "png"])
|
|
@@ -75,20 +75,14 @@ if uploaded_file is not None:
|
|
| 75 |
# Combine all extracted texts into a single string
|
| 76 |
english_text = ' '.join(extracted_texts)
|
| 77 |
|
| 78 |
-
# Translate English text to Persian using
|
| 79 |
st.subheader("Translated Persian Text:")
|
| 80 |
if english_text:
|
| 81 |
with st.spinner("Translating text..."):
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
'q': english_text,
|
| 85 |
-
'source': 'en',
|
| 86 |
-
'target': 'fa'
|
| 87 |
-
})
|
| 88 |
-
if translation_response.status_code == 200:
|
| 89 |
-
persian_text = translation_response.json()['translatedText']
|
| 90 |
st.write(persian_text)
|
| 91 |
-
|
| 92 |
-
st.write("Translation failed
|
| 93 |
else:
|
| 94 |
st.write("No text to translate.")
|
|
|
|
| 40 |
import easyocr
|
| 41 |
from PIL import Image
|
| 42 |
import numpy as np
|
| 43 |
+
from deep_translator import GoogleTranslator
|
| 44 |
|
| 45 |
# Initialize EasyOCR Reader
|
| 46 |
+
reader = easyocr.Reader(['en']) # Initialize reader for English
|
| 47 |
|
| 48 |
+
st.title("Image to Text Extraction and Translation Using EasyOCR and Translation Service")
|
| 49 |
|
| 50 |
# File uploader for images
|
| 51 |
uploaded_file = st.file_uploader("Choose an image... (JPEG, PNG)", type=["jpg", "jpeg", "png"])
|
|
|
|
| 75 |
# Combine all extracted texts into a single string
|
| 76 |
english_text = ' '.join(extracted_texts)
|
| 77 |
|
| 78 |
+
# Translate English text to Persian using Google Translator
|
| 79 |
st.subheader("Translated Persian Text:")
|
| 80 |
if english_text:
|
| 81 |
with st.spinner("Translating text..."):
|
| 82 |
+
try:
|
| 83 |
+
persian_text = GoogleTranslator(source='en', target='fa').translate(english_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
st.write(persian_text)
|
| 85 |
+
except Exception as e:
|
| 86 |
+
st.write(f"Translation failed: {e}")
|
| 87 |
else:
|
| 88 |
st.write("No text to translate.")
|