Spaces:
Build error
Build error
Commit ·
03048fe
1
Parent(s): 0ec220d
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,15 +5,19 @@ from PIL import Image
|
|
| 5 |
from gradio_client import Client
|
| 6 |
from googletrans import Translator
|
| 7 |
import cv2
|
|
|
|
| 8 |
|
| 9 |
def trans(text, lang='ta'):
|
| 10 |
translator = Translator()
|
| 11 |
out = translator.translate(text, dest=lang)
|
| 12 |
tts = gt.gTTS(text=out.text, lang=lang)
|
|
|
|
| 13 |
return "done"
|
| 14 |
|
| 15 |
-
def object_recognition(
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
API_URL = "https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-large"
|
| 18 |
headers = {"Authorization": "Bearer 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"}
|
| 19 |
|
|
@@ -25,22 +29,26 @@ def object_recognition(image,lang):
|
|
| 25 |
|
| 26 |
output = response.json()
|
| 27 |
text = output[0]['generated_text']
|
|
|
|
| 28 |
op = trans(text, lang)
|
| 29 |
return op
|
| 30 |
|
| 31 |
-
def ocr_detection(
|
|
|
|
|
|
|
| 32 |
|
| 33 |
client = Client("https://kneelesh48-tesseract-ocr.hf.space/")
|
| 34 |
result = client.predict(image, "afr", api_name="/tesseract-ocr")
|
| 35 |
print(result)
|
| 36 |
-
|
|
|
|
| 37 |
return op
|
| 38 |
|
| 39 |
-
def operator(
|
| 40 |
if value == "1":
|
| 41 |
-
op = object_recognition(
|
| 42 |
elif value == "2":
|
| 43 |
-
op = ocr_detection(
|
| 44 |
else:
|
| 45 |
op = trans("Sorry, I can't perform this operation.", lang)
|
| 46 |
return op
|
|
|
|
| 5 |
from gradio_client import Client
|
| 6 |
from googletrans import Translator
|
| 7 |
import cv2
|
| 8 |
+
import numpy as np
|
| 9 |
|
| 10 |
def trans(text, lang='ta'):
|
| 11 |
translator = Translator()
|
| 12 |
out = translator.translate(text, dest=lang)
|
| 13 |
tts = gt.gTTS(text=out.text, lang=lang)
|
| 14 |
+
tts.save("audio.mp3")
|
| 15 |
return "done"
|
| 16 |
|
| 17 |
+
def object_recognition(image_array, lang):
|
| 18 |
+
# Convert the NumPy array to PIL Image
|
| 19 |
+
image = Image.fromarray(image_array)
|
| 20 |
+
|
| 21 |
API_URL = "https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-large"
|
| 22 |
headers = {"Authorization": "Bearer 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"}
|
| 23 |
|
|
|
|
| 29 |
|
| 30 |
output = response.json()
|
| 31 |
text = output[0]['generated_text']
|
| 32 |
+
text = "Object recognition result for the captured image."
|
| 33 |
op = trans(text, lang)
|
| 34 |
return op
|
| 35 |
|
| 36 |
+
def ocr_detection(image_array, lang):
|
| 37 |
+
# Convert the NumPy array to PIL Image
|
| 38 |
+
image = Image.fromarray(image_array)
|
| 39 |
|
| 40 |
client = Client("https://kneelesh48-tesseract-ocr.hf.space/")
|
| 41 |
result = client.predict(image, "afr", api_name="/tesseract-ocr")
|
| 42 |
print(result)
|
| 43 |
+
text = "OCR detection result for the captured image."
|
| 44 |
+
op = trans(text, lang)
|
| 45 |
return op
|
| 46 |
|
| 47 |
+
def operator(image_array, value, lang):
|
| 48 |
if value == "1":
|
| 49 |
+
op = object_recognition(image_array, lang)
|
| 50 |
elif value == "2":
|
| 51 |
+
op = ocr_detection(image_array, lang)
|
| 52 |
else:
|
| 53 |
op = trans("Sorry, I can't perform this operation.", lang)
|
| 54 |
return op
|