rmayormartins
commited on
Commit
·
d209a4c
1
Parent(s):
89073fe
Subindo arquivos37733
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
from PIL import Image
|
@@ -74,7 +75,18 @@ def process_image(image):
|
|
74 |
|
75 |
# Texto para voz
|
76 |
tts = gTTS(text=translated_description, lang='pt')
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
# Retornar imagem com detecções, descrição e áudio
|
80 |
return Image.fromarray(detected_image), translated_description, "output.mp3"
|
|
|
1 |
import os
|
2 |
+
import time
|
3 |
import gradio as gr
|
4 |
import torch
|
5 |
from PIL import Image
|
|
|
75 |
|
76 |
# Texto para voz
|
77 |
tts = gTTS(text=translated_description, lang='pt')
|
78 |
+
attempts = 0
|
79 |
+
while attempts < 5:
|
80 |
+
try:
|
81 |
+
tts.save("output.mp3")
|
82 |
+
break
|
83 |
+
except gTTS.tts.gTTSError as e:
|
84 |
+
if e.r.status_code == 429:
|
85 |
+
print("Too many requests. Waiting before retrying...")
|
86 |
+
time.sleep(5)
|
87 |
+
attempts += 1
|
88 |
+
else:
|
89 |
+
raise e
|
90 |
|
91 |
# Retornar imagem com detecções, descrição e áudio
|
92 |
return Image.fromarray(detected_image), translated_description, "output.mp3"
|