Update main.py
Browse files
main.py
CHANGED
|
@@ -11,6 +11,10 @@ import time
|
|
| 11 |
import json
|
| 12 |
import subprocess
|
| 13 |
import asyncio
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
from gemini_webapi import GeminiClient
|
| 16 |
from gemini_webapi.constants import Model
|
|
@@ -23,19 +27,19 @@ os.makedirs("static/processed", exist_ok=True)
|
|
| 23 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 24 |
|
| 25 |
# Cookies extraídos do Request Header (usar variáveis de ambiente para a nuvem)
|
| 26 |
-
Secure_1PSID = os.getenv("GEMINI_SECURE_1PSID", "
|
| 27 |
-
Secure_1PSIDTS = os.getenv("GEMINI_SECURE_1PSIDTS", "
|
| 28 |
|
| 29 |
subtitle_gem = None
|
| 30 |
|
| 31 |
@app.on_event("startup")
|
| 32 |
async def startup_event():
|
| 33 |
global client, subtitle_gem
|
| 34 |
-
|
| 35 |
client = GeminiClient(Secure_1PSID, Secure_1PSIDTS, proxy=None)
|
| 36 |
# auto_refresh=True fará com que o token __Secure-1PSIDTS seja renovado automaticamente
|
| 37 |
await client.init(timeout=180, auto_close=False, close_delay=300, auto_refresh=True)
|
| 38 |
-
|
| 39 |
|
| 40 |
# Configurar o Gemini Gem (System Prompt) para a tradução de legendas
|
| 41 |
try:
|
|
@@ -81,13 +85,13 @@ Eu ia, mas aí percebi que esqueci minhas chaves.
|
|
| 81 |
|
| 82 |
if existing_gem:
|
| 83 |
subtitle_gem = existing_gem
|
| 84 |
-
|
| 85 |
else:
|
| 86 |
subtitle_gem = await client.create_gem(name=gem_name, prompt=gem_prompt, description="Gem otimizado para legenda SRT em pt-BR")
|
| 87 |
-
|
| 88 |
|
| 89 |
except Exception as e:
|
| 90 |
-
|
| 91 |
|
| 92 |
@app.get("/")
|
| 93 |
def root():
|
|
|
|
| 11 |
import json
|
| 12 |
import subprocess
|
| 13 |
import asyncio
|
| 14 |
+
import logging
|
| 15 |
+
|
| 16 |
+
logging.basicConfig(level=logging.INFO, format='%(levelname)s:\t %(message)s')
|
| 17 |
+
logger = logging.getLogger(__name__)
|
| 18 |
|
| 19 |
from gemini_webapi import GeminiClient
|
| 20 |
from gemini_webapi.constants import Model
|
|
|
|
| 27 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 28 |
|
| 29 |
# Cookies extraídos do Request Header (usar variáveis de ambiente para a nuvem)
|
| 30 |
+
Secure_1PSID = os.getenv("GEMINI_SECURE_1PSID", "PRIVATE")
|
| 31 |
+
Secure_1PSIDTS = os.getenv("GEMINI_SECURE_1PSIDTS", "PRIVATE")
|
| 32 |
|
| 33 |
subtitle_gem = None
|
| 34 |
|
| 35 |
@app.on_event("startup")
|
| 36 |
async def startup_event():
|
| 37 |
global client, subtitle_gem
|
| 38 |
+
logger.info("Iniciando cliente do Gemini em plano de fundo...")
|
| 39 |
client = GeminiClient(Secure_1PSID, Secure_1PSIDTS, proxy=None)
|
| 40 |
# auto_refresh=True fará com que o token __Secure-1PSIDTS seja renovado automaticamente
|
| 41 |
await client.init(timeout=180, auto_close=False, close_delay=300, auto_refresh=True)
|
| 42 |
+
logger.info("Cliente Gemini-API inicializado com sucesso!")
|
| 43 |
|
| 44 |
# Configurar o Gemini Gem (System Prompt) para a tradução de legendas
|
| 45 |
try:
|
|
|
|
| 85 |
|
| 86 |
if existing_gem:
|
| 87 |
subtitle_gem = existing_gem
|
| 88 |
+
logger.info(f"✨ Gem '{gem_name}' encontrado e carregado na conta.")
|
| 89 |
else:
|
| 90 |
subtitle_gem = await client.create_gem(name=gem_name, prompt=gem_prompt, description="Gem otimizado para legenda SRT em pt-BR")
|
| 91 |
+
logger.info(f"✨ Gem '{gem_name}' criado com sucesso na conta.")
|
| 92 |
|
| 93 |
except Exception as e:
|
| 94 |
+
logger.error(f"⚠️ Aviso: Não foi possivel carregar/criar Gem de legendas. Erro: {e}")
|
| 95 |
|
| 96 |
@app.get("/")
|
| 97 |
def root():
|