Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,57 +4,61 @@ from fastapi.responses import HTMLResponse
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
-
# --- ARSENAL DE CHAVES (Pool de 15 chaves
|
| 8 |
-
#
|
| 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 (
|
| 13 |
-
# Tradução dos
|
| 14 |
MODEL_MAP = {
|
| 15 |
-
"
|
| 16 |
"aria_med": "google/gemini-2.5-pro:free",
|
| 17 |
-
"aria_logic": "qwen/
|
| 18 |
-
"
|
| 19 |
-
"
|
|
|
|
| 20 |
}
|
| 21 |
|
| 22 |
@app.get("/", response_class=HTMLResponse)
|
| 23 |
async def root():
|
| 24 |
-
# Painel de
|
| 25 |
-
status_color = "#
|
| 26 |
-
status_text = "🟢
|
| 27 |
|
| 28 |
return f"""
|
| 29 |
-
<
|
| 30 |
-
<
|
| 31 |
-
|
| 32 |
-
<
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
"""
|
| 40 |
|
| 41 |
@app.post("/v1/chat/completions")
|
| 42 |
async def proxy(request: Request):
|
| 43 |
if not KEYS:
|
| 44 |
-
return Response(content='{{"error": "CEO,
|
| 45 |
|
| 46 |
try:
|
| 47 |
body = await request.json()
|
| 48 |
model_requested = body.get("model", "")
|
| 49 |
|
| 50 |
-
# 1. LIMPEZA: Remove
|
| 51 |
clean_model = model_requested.replace("fortune/", "")
|
| 52 |
|
| 53 |
-
# 2. TRADUÇÃO:
|
| 54 |
target_model = MODEL_MAP.get(clean_model, clean_model)
|
| 55 |
body["model"] = target_model
|
| 56 |
|
| 57 |
-
# 3. ROTAÇÃO
|
| 58 |
selected_key = random.choice(KEYS)
|
| 59 |
|
| 60 |
headers = {
|
|
@@ -64,21 +68,20 @@ async def proxy(request: Request):
|
|
| 64 |
"Content-Type": "application/json"
|
| 65 |
}
|
| 66 |
|
| 67 |
-
# 4. EXECUÇÃO:
|
| 68 |
async with httpx.AsyncClient() as client:
|
| 69 |
response = await client.post(
|
| 70 |
"https://openrouter.ai/api/v1/chat/completions",
|
| 71 |
json=body,
|
| 72 |
headers=headers,
|
| 73 |
-
timeout=120.0
|
| 74 |
)
|
| 75 |
return Response(content=response.content, status_code=response.status_code)
|
| 76 |
|
| 77 |
except Exception as e:
|
| 78 |
-
return Response(content=f'{{"error": "
|
| 79 |
|
| 80 |
-
# --- IGNIÇÃO DO
|
| 81 |
-
# Garante que o servidor uvicorn permaneça ativo na porta padrão do Hugging Face
|
| 82 |
if __name__ == "__main__":
|
| 83 |
-
print("
|
| 84 |
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) ---
|
| 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 (Grelha 2026) ---
|
| 13 |
+
# Tradução dos comandos do CEO para os IDs reais do OpenRouter
|
| 14 |
MODEL_MAP = {
|
| 15 |
+
"aria_brain": "nvidia/nemotron-3-super:free", # O novo cérebro 120B (Mamba-Transformer)
|
| 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", # Especialista em Word/Excel para o Nexos
|
| 20 |
+
"aria_default": "nvidia/nemotron-3-super:free"
|
| 21 |
}
|
| 22 |
|
| 23 |
@app.get("/", response_class=HTMLResponse)
|
| 24 |
async def root():
|
| 25 |
+
# Painel de Status para o CEO Fortune
|
| 26 |
+
status_color = "#00f2ff" if KEYS else "#ff0055"
|
| 27 |
+
status_text = "🟢 NEMOTRON CORE ACTIVE" if KEYS else "🔴 SHIELD OFFLINE"
|
| 28 |
|
| 29 |
return f"""
|
| 30 |
+
<html>
|
| 31 |
+
<head><title>Aria Shield V2.6</title></head>
|
| 32 |
+
<body style='background:#050505; color:#e0e0e0; font-family:monospace; text-align:center; padding-top:100px;'>
|
| 33 |
+
<div style='border: 1px solid {status_color}; display:inline-block; padding:40px; background:#0a0a0a; box-shadow: 0 0 20px {status_color}33;'>
|
| 34 |
+
<h1 style='color:{status_color}; letter-spacing:5px;'>ARIA SOVEREIGN SHIELD V2.6</h1>
|
| 35 |
+
<p style='font-size:1.2em;'>Arsenal: <strong>{len(KEYS)} Chaves Ativas</strong></p>
|
| 36 |
+
<p style='color:#666;'>Local: Beira, Sofala, MZ</p>
|
| 37 |
+
<hr style='border:0; border-top:1px solid #222; margin:30px 0;'>
|
| 38 |
+
<p style='font-weight:bold; font-size:1.4em;'>{status_text}</p>
|
| 39 |
+
<p style='color:#444; font-size:0.8em;'>Primary Brain: Nemotron 3 Super (1M Context Support)</p>
|
| 40 |
+
</div>
|
| 41 |
+
</body>
|
| 42 |
+
</html>
|
| 43 |
"""
|
| 44 |
|
| 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 está vazio!"}}', status_code=500)
|
| 49 |
|
| 50 |
try:
|
| 51 |
body = await request.json()
|
| 52 |
model_requested = body.get("model", "")
|
| 53 |
|
| 54 |
+
# 1. LIMPEZA DE PREFIXO: Remove "fortune/" para compatibilidade
|
| 55 |
clean_model = model_requested.replace("fortune/", "")
|
| 56 |
|
| 57 |
+
# 2. TRADUÇÃO: Mapeia o apelido para o ID técnico do OpenRouter
|
| 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 |
"Content-Type": "application/json"
|
| 69 |
}
|
| 70 |
|
| 71 |
+
# 4. EXECUÇÃO: Encaminhamento para o OpenRouter com timeout estendido
|
| 72 |
async with httpx.AsyncClient() as client:
|
| 73 |
response = await client.post(
|
| 74 |
"https://openrouter.ai/api/v1/chat/completions",
|
| 75 |
json=body,
|
| 76 |
headers=headers,
|
| 77 |
+
timeout=120.0
|
| 78 |
)
|
| 79 |
return Response(content=response.content, status_code=response.status_code)
|
| 80 |
|
| 81 |
except Exception as e:
|
| 82 |
+
return Response(content=f'{{"error": "Shield Bridge Failure: {str(e)}"}}', status_code=500)
|
| 83 |
|
| 84 |
+
# --- IGNIÇÃO DO SISTEMA (Prevenção de Exit Code 0) ---
|
|
|
|
| 85 |
if __name__ == "__main__":
|
| 86 |
+
print("🛰️ Aria Shield V2.6: Iniciando protocolos em Beira...")
|
| 87 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|