Update app.py
Browse files
app.py
CHANGED
|
@@ -732,12 +732,38 @@ async def get_groq_srt_base(url: str, language: Optional[str] = None, temperatur
|
|
| 732 |
|
| 733 |
print(f"🧠 [Groq] Enviando URL para processamento (whisper-large-v3)...")
|
| 734 |
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 741 |
|
| 742 |
# Converter para SRT (Word Level)
|
| 743 |
srt_word = groq_json_to_srt(result)
|
|
|
|
| 732 |
|
| 733 |
print(f"🧠 [Groq] Enviando URL para processamento (whisper-large-v3)...")
|
| 734 |
|
| 735 |
+
max_retries = 3
|
| 736 |
+
for attempt in range(max_retries):
|
| 737 |
+
try:
|
| 738 |
+
response_groq = requests.post(groq_url, headers=headers, files=files, timeout=300)
|
| 739 |
+
|
| 740 |
+
if response_groq.status_code == 200:
|
| 741 |
+
result = response_groq.json()
|
| 742 |
+
break
|
| 743 |
+
|
| 744 |
+
# Check for specific "context deadline exceeded" or 5xx errors
|
| 745 |
+
error_msg = response_groq.text.lower()
|
| 746 |
+
is_deadline_error = "context deadline exceeded" in error_msg
|
| 747 |
+
is_server_error = response_groq.status_code >= 500
|
| 748 |
+
|
| 749 |
+
if (is_deadline_error or is_server_error) and attempt < max_retries - 1:
|
| 750 |
+
wait_time = 2 * (attempt + 1)
|
| 751 |
+
print(f"⚠️ Erro transiente Groq ({response_groq.status_code}): {error_msg[:100]}... Tentando novamente em {wait_time}s...")
|
| 752 |
+
await asyncio.sleep(wait_time)
|
| 753 |
+
|
| 754 |
+
# Reset files pointer if needed (though for URL it's fine, but if we sent file-like obj we'd need seek(0))
|
| 755 |
+
# Since we send tuples with strings/None, we don't need to reset anything for 'files' dict here.
|
| 756 |
+
continue
|
| 757 |
+
|
| 758 |
+
raise HTTPException(status_code=response_groq.status_code, detail=f"Erro Groq: {response_groq.text}")
|
| 759 |
+
|
| 760 |
+
except requests.RequestException as e:
|
| 761 |
+
if attempt < max_retries - 1:
|
| 762 |
+
print(f"⚠️ Erro de conexão Groq: {e}. Retentando...")
|
| 763 |
+
await asyncio.sleep(2)
|
| 764 |
+
continue
|
| 765 |
+
raise HTTPException(status_code=500, detail=f"Erro de conexão com Groq: {str(e)}")
|
| 766 |
+
|
| 767 |
|
| 768 |
# Converter para SRT (Word Level)
|
| 769 |
srt_word = groq_json_to_srt(result)
|