Update main.py
Browse files
main.py
CHANGED
|
@@ -387,26 +387,43 @@ Se o contexto enviado pelo usuário não for verdadeiro ou estiver impreciso, ig
|
|
| 387 |
if cut_file and os.path.exists(cut_file.name): os.unlink(cut_file.name)
|
| 388 |
|
| 389 |
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
video_url: Optional[str] = None
|
| 393 |
-
image_url: Optional[str] = None
|
| 394 |
-
context: Optional[str] = None
|
| 395 |
-
discord_id: Optional[int] = 1
|
| 396 |
-
|
| 397 |
-
@app.post("/filter")
|
| 398 |
-
async def filter_endpoint(request: FilterRequest):
|
| 399 |
if not client:
|
| 400 |
raise HTTPException(status_code=500, detail="Gemini client is not initialized")
|
| 401 |
temp_file = None
|
| 402 |
try:
|
| 403 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
if not url_to_download:
|
| 405 |
-
raise HTTPException(status_code=400, detail="
|
| 406 |
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
agent_name = bot_names.get(discord_id, "Sistema")
|
| 410 |
|
| 411 |
try:
|
| 412 |
import urllib.parse
|
|
@@ -441,7 +458,7 @@ async def filter_endpoint(request: FilterRequest):
|
|
| 441 |
|
| 442 |
media_path_to_analyze = temp_file.name
|
| 443 |
|
| 444 |
-
contexto_add = f"\n\nContexto Adicional / Legenda Original:\n{
|
| 445 |
|
| 446 |
prompt = f"""Você é DIANA, a Curadora de Conteúdo da @girlsmoodaily no Instagram.
|
| 447 |
|
|
@@ -556,9 +573,23 @@ Reprovando (exemplo 2):
|
|
| 556 |
timeout=5
|
| 557 |
)
|
| 558 |
except Exception as e:
|
| 559 |
-
print(f"⚠️ Erro ao enviar
|
| 560 |
-
|
| 561 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
except Exception as e:
|
| 563 |
raise HTTPException(status_code=500, detail=f"Erro interno: {str(e)}")
|
| 564 |
finally:
|
|
|
|
| 387 |
if cut_file and os.path.exists(cut_file.name): os.unlink(cut_file.name)
|
| 388 |
|
| 389 |
|
| 390 |
+
@app.api_route("/filter-girlsmoodaily", methods=["GET", "POST"])
|
| 391 |
+
async def filter_endpoint():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
if not client:
|
| 393 |
raise HTTPException(status_code=500, detail="Gemini client is not initialized")
|
| 394 |
temp_file = None
|
| 395 |
try:
|
| 396 |
+
supabase_url = os.getenv("SUPABASE_URL", "").rstrip("/")
|
| 397 |
+
supabase_key = os.getenv("SUPABASE_KEY", "")
|
| 398 |
+
if not supabase_url or not supabase_key:
|
| 399 |
+
raise HTTPException(status_code=500, detail="Credenciais do Supabase não configuradas no ambiente.")
|
| 400 |
+
|
| 401 |
+
headers = {
|
| 402 |
+
"apikey": supabase_key,
|
| 403 |
+
"Authorization": f"Bearer {supabase_key}",
|
| 404 |
+
"Content-Type": "application/json"
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
# Buscar 1 post pendente para filtro
|
| 408 |
+
select_url = f"{supabase_url}/rest/v1/posts?select=*&filter_message=is.null&limit=1"
|
| 409 |
+
res_get = requests.get(select_url, headers=headers, timeout=10)
|
| 410 |
+
if not res_get.ok:
|
| 411 |
+
raise HTTPException(status_code=500, detail=f"Erro ao ler posts: {res_get.text}")
|
| 412 |
+
|
| 413 |
+
records = res_get.json()
|
| 414 |
+
if not records:
|
| 415 |
+
return {"status": "ok", "message": "Nenhuma postagem pendente para ser filtrada."}
|
| 416 |
+
|
| 417 |
+
record = records[0]
|
| 418 |
+
record_id = record.get("id")
|
| 419 |
+
url_to_download = record.get("ig_post_url")
|
| 420 |
+
context_text = record.get("ig_caption", "")
|
| 421 |
+
|
| 422 |
if not url_to_download:
|
| 423 |
+
raise HTTPException(status_code=400, detail=f"Registro ID {record_id} falhou: ig_post_url inválida.")
|
| 424 |
|
| 425 |
+
discord_id = 1
|
| 426 |
+
agent_name = "Diana"
|
|
|
|
| 427 |
|
| 428 |
try:
|
| 429 |
import urllib.parse
|
|
|
|
| 458 |
|
| 459 |
media_path_to_analyze = temp_file.name
|
| 460 |
|
| 461 |
+
contexto_add = f"\n\nContexto Adicional / Legenda Original:\n{context_text}" if context_text else ""
|
| 462 |
|
| 463 |
prompt = f"""Você é DIANA, a Curadora de Conteúdo da @girlsmoodaily no Instagram.
|
| 464 |
|
|
|
|
| 573 |
timeout=5
|
| 574 |
)
|
| 575 |
except Exception as e:
|
| 576 |
+
print(f"⚠️ Erro ao enviar log para o Discord: {e}")
|
| 577 |
+
|
| 578 |
+
# Atualizar no Supabase
|
| 579 |
+
update_url = f"{supabase_url}/rest/v1/posts?id=eq.{record_id}"
|
| 580 |
+
patch_payload = {
|
| 581 |
+
"filter_message": filter_data.get("filter_message"),
|
| 582 |
+
"approved_filter": filter_data.get("approved_filter")
|
| 583 |
+
}
|
| 584 |
+
res_patch = requests.patch(update_url, headers=headers, json=patch_payload, timeout=10)
|
| 585 |
+
if not res_patch.ok:
|
| 586 |
+
print(f"⚠️ Erro ao atualizar Supabase: {res_patch.text}")
|
| 587 |
+
|
| 588 |
+
return {
|
| 589 |
+
"success": True,
|
| 590 |
+
"record_id": record_id,
|
| 591 |
+
"filter_data": filter_data
|
| 592 |
+
}
|
| 593 |
except Exception as e:
|
| 594 |
raise HTTPException(status_code=500, detail=f"Erro interno: {str(e)}")
|
| 595 |
finally:
|