Update main.py
Browse files
main.py
CHANGED
|
@@ -217,6 +217,7 @@ class ProcessUrlRequest(BaseModel):
|
|
| 217 |
version: str # "recurvepop" ou "girlsmoodaily"
|
| 218 |
raw_url: Optional[bool] = True
|
| 219 |
text_cut: Optional[bool] = True
|
|
|
|
| 220 |
|
| 221 |
@app.post("/process-url")
|
| 222 |
async def process_url_endpoint(request: ProcessUrlRequest, background_tasks: BackgroundTasks):
|
|
@@ -634,7 +635,7 @@ Objetivo: O foco é detectar se o vídeo foi "re-editado" com textos informativo
|
|
| 634 |
|
| 635 |
# Legendas
|
| 636 |
needs_legenda = result_data.get("legenda", False)
|
| 637 |
-
if needs_legenda:
|
| 638 |
print(f"🎙️ [{time.time()-t_start:.1f}s] Resolvendo legendas (Groq task + Gemini translate)...")
|
| 639 |
try:
|
| 640 |
if groq_task:
|
|
@@ -1215,7 +1216,7 @@ async def process_account_endpoint(account: str):
|
|
| 1215 |
# 5. Gerar legendas se necessário
|
| 1216 |
needs_legenda = result_data.get("legenda", False)
|
| 1217 |
srt_for_export = None
|
| 1218 |
-
if needs_legenda:
|
| 1219 |
print(f"🎙️ [{time.time()-t_start:.1f}s] Resolvendo legendas (Groq task + Gemini translate)...")
|
| 1220 |
try:
|
| 1221 |
if groq_task:
|
|
@@ -2362,6 +2363,7 @@ async def generate_subtitle_groq(request: GroqRequest):
|
|
| 2362 |
class GeminiSubtitleRequest(BaseModel):
|
| 2363 |
url: str
|
| 2364 |
has_bg_music: Optional[bool] = False
|
|
|
|
| 2365 |
context: Optional[str] = "N/A"
|
| 2366 |
model: Optional[str] = "flash"
|
| 2367 |
time_start: Optional[float] = None
|
|
@@ -2372,9 +2374,23 @@ async def generate_subtitle(request: GeminiSubtitleRequest):
|
|
| 2372 |
if not client: raise HTTPException(status_code=500, detail="Gemini client is not initialized")
|
| 2373 |
try:
|
| 2374 |
srt_filtered, _, audio_url, word_level_text = await get_groq_srt_base(
|
| 2375 |
-
request.url,
|
| 2376 |
)
|
| 2377 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2378 |
filename = audio_url.split("/")[-1]
|
| 2379 |
processed_audio_path = os.path.join("static", filename)
|
| 2380 |
if not os.path.exists(processed_audio_path): processed_audio_path = os.path.join("static", "processed", filename)
|
|
|
|
| 217 |
version: str # "recurvepop" ou "girlsmoodaily"
|
| 218 |
raw_url: Optional[bool] = True
|
| 219 |
text_cut: Optional[bool] = True
|
| 220 |
+
translate: Optional[bool] = True
|
| 221 |
|
| 222 |
@app.post("/process-url")
|
| 223 |
async def process_url_endpoint(request: ProcessUrlRequest, background_tasks: BackgroundTasks):
|
|
|
|
| 635 |
|
| 636 |
# Legendas
|
| 637 |
needs_legenda = result_data.get("legenda", False)
|
| 638 |
+
if needs_legenda and request.translate:
|
| 639 |
print(f"🎙️ [{time.time()-t_start:.1f}s] Resolvendo legendas (Groq task + Gemini translate)...")
|
| 640 |
try:
|
| 641 |
if groq_task:
|
|
|
|
| 1216 |
# 5. Gerar legendas se necessário
|
| 1217 |
needs_legenda = result_data.get("legenda", False)
|
| 1218 |
srt_for_export = None
|
| 1219 |
+
if needs_legenda and record.get("translate", True):
|
| 1220 |
print(f"🎙️ [{time.time()-t_start:.1f}s] Resolvendo legendas (Groq task + Gemini translate)...")
|
| 1221 |
try:
|
| 1222 |
if groq_task:
|
|
|
|
| 2363 |
class GeminiSubtitleRequest(BaseModel):
|
| 2364 |
url: str
|
| 2365 |
has_bg_music: Optional[bool] = False
|
| 2366 |
+
translate: Optional[bool] = True
|
| 2367 |
context: Optional[str] = "N/A"
|
| 2368 |
model: Optional[str] = "flash"
|
| 2369 |
time_start: Optional[float] = None
|
|
|
|
| 2374 |
if not client: raise HTTPException(status_code=500, detail="Gemini client is not initialized")
|
| 2375 |
try:
|
| 2376 |
srt_filtered, _, audio_url, word_level_text = await get_groq_srt_base(
|
| 2377 |
+
request.url, None, 0.4, request.has_bg_music, request.time_start, request.time_end
|
| 2378 |
)
|
| 2379 |
|
| 2380 |
+
# Se não for solicitado tradução/limpeza via Gemini, retorna o original direto
|
| 2381 |
+
if not request.translate:
|
| 2382 |
+
final_srt = srt_filtered
|
| 2383 |
+
if request.time_start and request.time_start > 0:
|
| 2384 |
+
final_srt = shift_srt_timestamps(final_srt, request.time_start)
|
| 2385 |
+
|
| 2386 |
+
return JSONResponse(content={
|
| 2387 |
+
"srt": final_srt,
|
| 2388 |
+
"original_srt": final_srt,
|
| 2389 |
+
"srt_word_level": word_level_text,
|
| 2390 |
+
"used_audio_processed": True,
|
| 2391 |
+
"translated": False
|
| 2392 |
+
})
|
| 2393 |
+
|
| 2394 |
filename = audio_url.split("/")[-1]
|
| 2395 |
processed_audio_path = os.path.join("static", filename)
|
| 2396 |
if not os.path.exists(processed_audio_path): processed_audio_path = os.path.join("static", "processed", filename)
|