Spaces:
Sleeping
Sleeping
Commit ·
c9b1147
1
Parent(s): 3c3aa88
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ from googletrans import Translator
|
|
| 7 |
import cv2
|
| 8 |
import numpy as np
|
| 9 |
import tempfile
|
|
|
|
| 10 |
|
| 11 |
def trans(text, lang='ta'):
|
| 12 |
translator = Translator()
|
|
@@ -37,16 +38,27 @@ def object_recognition(image_array, lang):
|
|
| 37 |
return audio_file
|
| 38 |
|
| 39 |
def ocr_detection(image_array, lang):
|
| 40 |
-
# Convert the NumPy array to PIL Image
|
| 41 |
image = Image.fromarray(image_array)
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
return audio_file
|
| 49 |
|
|
|
|
| 50 |
def operator(image_array, value, lang):
|
| 51 |
if value == "1":
|
| 52 |
audio_file = object_recognition(image_array, lang)
|
|
|
|
| 7 |
import cv2
|
| 8 |
import numpy as np
|
| 9 |
import tempfile
|
| 10 |
+
import base64
|
| 11 |
|
| 12 |
def trans(text, lang='ta'):
|
| 13 |
translator = Translator()
|
|
|
|
| 38 |
return audio_file
|
| 39 |
|
| 40 |
def ocr_detection(image_array, lang):
|
|
|
|
| 41 |
image = Image.fromarray(image_array)
|
| 42 |
|
| 43 |
+
buffered = BytesIO()
|
| 44 |
+
image.save(buffered, format="PNG")
|
| 45 |
+
image_base64 = base64.b64encode(buffered.getvalue()).decode()
|
| 46 |
+
|
| 47 |
+
response = requests.post("https://pragnakalp-ocr-image-to-text.hf.space/run/predict", json={
|
| 48 |
+
"data": [
|
| 49 |
+
"PaddleOCR",
|
| 50 |
+
f"data:image/png;base64,{image_base64}",
|
| 51 |
+
]
|
| 52 |
+
}).json()
|
| 53 |
+
|
| 54 |
+
data = response.get("data", [])
|
| 55 |
+
|
| 56 |
+
text = " ".join(data)
|
| 57 |
+
audio_file = trans(text, lang)
|
| 58 |
+
|
| 59 |
return audio_file
|
| 60 |
|
| 61 |
+
|
| 62 |
def operator(image_array, value, lang):
|
| 63 |
if value == "1":
|
| 64 |
audio_file = object_recognition(image_array, lang)
|