Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,39 +4,42 @@ from fastapi.responses import HTMLResponse
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
-
# --- ARSENAL DE CHAVES (Pool de 15 chaves - Operação Beira) ---
|
| 8 |
-
# Carrega as chaves do OpenRouter configuradas nos Secrets
|
| 9 |
KEYS = [os.getenv(f"OR_KEY_{i}") for i in range(1, 16)]
|
| 10 |
KEYS = [k for k in KEYS if k and k.strip()]
|
| 11 |
|
| 12 |
-
# --- MAPEAMENTO UNIFICADO ARIA (
|
| 13 |
-
# Tradução dos comandos do CEO para os IDs
|
| 14 |
MODEL_MAP = {
|
| 15 |
-
"
|
|
|
|
| 16 |
"aria_med": "google/gemini-2.5-pro:free",
|
| 17 |
-
"aria_logic": "qwen/qwen3-coder-480b:free",
|
| 18 |
"aria_vision": "nvidia/nemotron-nano-12b-2-vl:free",
|
| 19 |
-
"aria_office": "minimax/minimax-m2.5:free",
|
| 20 |
-
"aria_default": "
|
| 21 |
}
|
| 22 |
|
| 23 |
@app.get("/", response_class=HTMLResponse)
|
| 24 |
async def root():
|
| 25 |
-
# Painel de Status para
|
| 26 |
-
status_color = "#
|
| 27 |
-
status_text = "🟢
|
| 28 |
|
| 29 |
return f"""
|
| 30 |
<html>
|
| 31 |
-
<head>
|
| 32 |
-
|
| 33 |
-
<
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
<
|
| 38 |
-
<p style='font-
|
| 39 |
-
<p style='color:#
|
|
|
|
|
|
|
|
|
|
| 40 |
</div>
|
| 41 |
</body>
|
| 42 |
</html>
|
|
@@ -45,20 +48,20 @@ async def root():
|
|
| 45 |
@app.post("/v1/chat/completions")
|
| 46 |
async def proxy(request: Request):
|
| 47 |
if not KEYS:
|
| 48 |
-
return Response(content='{{"error": "CEO, o arsenal de chaves
|
| 49 |
|
| 50 |
try:
|
| 51 |
body = await request.json()
|
| 52 |
model_requested = body.get("model", "")
|
| 53 |
|
| 54 |
-
# 1. LIMPEZA DE PREFIXO: Remove "fortune/" para
|
| 55 |
clean_model = model_requested.replace("fortune/", "")
|
| 56 |
|
| 57 |
-
# 2. TRADUÇÃO:
|
| 58 |
target_model = MODEL_MAP.get(clean_model, clean_model)
|
| 59 |
body["model"] = target_model
|
| 60 |
|
| 61 |
-
# 3. ROTAÇÃO DE CHAVES: Escolha aleatória para distribuir o tráfego
|
| 62 |
selected_key = random.choice(KEYS)
|
| 63 |
|
| 64 |
headers = {
|
|
@@ -68,7 +71,7 @@ async def proxy(request: Request):
|
|
| 68 |
"Content-Type": "application/json"
|
| 69 |
}
|
| 70 |
|
| 71 |
-
# 4. EXECUÇÃO: Encaminhamento para o OpenRouter com timeout
|
| 72 |
async with httpx.AsyncClient() as client:
|
| 73 |
response = await client.post(
|
| 74 |
"https://openrouter.ai/api/v1/chat/completions",
|
|
@@ -79,9 +82,9 @@ async def proxy(request: Request):
|
|
| 79 |
return Response(content=response.content, status_code=response.status_code)
|
| 80 |
|
| 81 |
except Exception as e:
|
| 82 |
-
return Response(content=f'{{"error": "
|
| 83 |
|
| 84 |
-
# --- IGNIÇÃO DO
|
| 85 |
if __name__ == "__main__":
|
| 86 |
-
print("🛰️ Aria Shield V2.6:
|
| 87 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
+
# --- ARSENAL DE CHAVES (Pool de 15 chaves - Operação Beira, MZ) ---
|
| 8 |
+
# Carrega as chaves do OpenRouter configuradas nos Secrets do Hugging Face
|
| 9 |
KEYS = [os.getenv(f"OR_KEY_{i}") for i in range(1, 16)]
|
| 10 |
KEYS = [k for k in KEYS if k and k.strip()]
|
| 11 |
|
| 12 |
+
# --- MAPEAMENTO UNIFICADO ARIA (Atualização Estratégica Qwen3) ---
|
| 13 |
+
# Tradução dos comandos do CEO para os IDs técnicos reais
|
| 14 |
MODEL_MAP = {
|
| 15 |
+
"aria_coder": "qwen/qwen3-coder:free", # O novo motor de elite para programação
|
| 16 |
+
"aria_brain": "nvidia/nemotron-3-super:free", # Raciocínio clínico massivo para a Vitalis
|
| 17 |
"aria_med": "google/gemini-2.5-pro:free",
|
|
|
|
| 18 |
"aria_vision": "nvidia/nemotron-nano-12b-2-vl:free",
|
| 19 |
+
"aria_office": "minimax/minimax-m2.5:free", # Gestão de documentos para a Nexos
|
| 20 |
+
"aria_default": "qwen/qwen3-coder:free" # Qwen3 Coder definido como padrão
|
| 21 |
}
|
| 22 |
|
| 23 |
@app.get("/", response_class=HTMLResponse)
|
| 24 |
async def root():
|
| 25 |
+
# Painel de Status Visual para monitorização em Beira
|
| 26 |
+
status_color = "#00ff88" if KEYS else "#ff4444"
|
| 27 |
+
status_text = "🟢 SISTEMA OPERACIONAL" if KEYS else "🔴 FALHA NAS CHAVES"
|
| 28 |
|
| 29 |
return f"""
|
| 30 |
<html>
|
| 31 |
+
<head>
|
| 32 |
+
<title>Aria Shield V2.6.1</title>
|
| 33 |
+
<meta charset="utf-8">
|
| 34 |
+
</head>
|
| 35 |
+
<body style='background:#0a0a0a; color:#e0e0e0; font-family:monospace; text-align:center; padding-top:80px;'>
|
| 36 |
+
<div style='border: 1px solid {status_color}; display:inline-block; padding:40px; border-radius:10px; background:#0f0f0f; box-shadow: 0 0 15px {status_color}22;'>
|
| 37 |
+
<h1 style='color:{status_color}; letter-spacing:4px;'>ARIA SOVEREIGN SHIELD V2.6.1</h1>
|
| 38 |
+
<p style='font-size:1.3em;'>Arsenal: <strong>{len(KEYS)} Chaves Ativas</strong></p>
|
| 39 |
+
<p style='color:#666;'>Localização: Beira, Sofala, Moçambique</p>
|
| 40 |
+
<hr style='border:0; border-top:1px solid #333; margin:25px 0;'>
|
| 41 |
+
<p style='font-weight:bold; font-size:1.4em;'>Status: {status_text}</p>
|
| 42 |
+
<p style='color:#0088ff; font-size:0.9em;'>Motor Ativo: Qwen3 Coder (Software Architecture Mode)</p>
|
| 43 |
</div>
|
| 44 |
</body>
|
| 45 |
</html>
|
|
|
|
| 48 |
@app.post("/v1/chat/completions")
|
| 49 |
async def proxy(request: Request):
|
| 50 |
if not KEYS:
|
| 51 |
+
return Response(content='{{"error": "CEO, o arsenal de 15 chaves não foi detetado!"}}', status_code=500)
|
| 52 |
|
| 53 |
try:
|
| 54 |
body = await request.json()
|
| 55 |
model_requested = body.get("model", "")
|
| 56 |
|
| 57 |
+
# 1. LIMPEZA DE PREFIXO: Remove "fortune/" para garantir que a ponte não falha
|
| 58 |
clean_model = model_requested.replace("fortune/", "")
|
| 59 |
|
| 60 |
+
# 2. TRADUÇÃO: Converte o apelido (ex: aria_coder) no ID oficial do OpenRouter
|
| 61 |
target_model = MODEL_MAP.get(clean_model, clean_model)
|
| 62 |
body["model"] = target_model
|
| 63 |
|
| 64 |
+
# 3. ROTAÇÃO DE CHAVES: Escolha aleatória para distribuir o tráfego e evitar limites
|
| 65 |
selected_key = random.choice(KEYS)
|
| 66 |
|
| 67 |
headers = {
|
|
|
|
| 71 |
"Content-Type": "application/json"
|
| 72 |
}
|
| 73 |
|
| 74 |
+
# 4. EXECUÇÃO: Encaminhamento para o OpenRouter com timeout para operações longas
|
| 75 |
async with httpx.AsyncClient() as client:
|
| 76 |
response = await client.post(
|
| 77 |
"https://openrouter.ai/api/v1/chat/completions",
|
|
|
|
| 82 |
return Response(content=response.content, status_code=response.status_code)
|
| 83 |
|
| 84 |
except Exception as e:
|
| 85 |
+
return Response(content=f'{{"error": "Falha na Ponte Shield: {str(e)}"}}', status_code=500)
|
| 86 |
|
| 87 |
+
# --- IGNIÇÃO DO SERVIDOR (Prevenção de Exit Code 0 no Hugging Face) ---
|
| 88 |
if __name__ == "__main__":
|
| 89 |
+
print("🛰️ Aria Shield V2.6.1: Operação Beira Iniciada...")
|
| 90 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|