SatyaDev13 commited on
Commit
69e9e9e
·
verified ·
1 Parent(s): 076cd11

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -1,13 +1,19 @@
1
- import os, time, json, logging, secrets, threading
 
 
 
 
 
 
2
  from typing import Optional, List
3
 
4
- logging.basicConfig(level=logging.INFO, format="%(asctime)s | %(message)s")
5
- logger = logging.getLogger("SaaS-API")
6
 
7
  import torch
8
  from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
9
  import spaces
10
- from fastapi import FastAPI, Security, HTTPException, Depends
 
11
  from fastapi.security import APIKeyHeader, HTTPBasic, HTTPBasicCredentials
12
  from fastapi.middleware.cors import CORSMiddleware
13
  from fastapi.responses import HTMLResponse
@@ -15,6 +21,9 @@ from pydantic import BaseModel, Field
15
 
16
  import agent_core as AC
17
 
 
 
 
18
  ADMIN_USER = os.environ.get("ADMIN_USER")
19
  ADMIN_PASS = os.environ.get("ADMIN_PASS")
20
  DB_FILE = "database.json"
@@ -116,7 +125,10 @@ class AgentRun(BaseModel):
116
  max_steps: int = 12
117
 
118
  # ================= APP =================
119
- app = FastAPI(title="Private AI")
 
 
 
120
  app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])
121
 
122
  api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False)
@@ -311,5 +323,5 @@ function delKey(key){{if(confirm('Konfirmasi penghapusan permanen API Key: '+key
311
  </script></body></html>"""
312
 
313
  if __name__ == "__main__":
314
- import uvicorn
315
- uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", "7860")))
 
1
+ import os
2
+ import sys
3
+ import time
4
+ import json
5
+ import logging
6
+ import secrets
7
+ import threading
8
  from typing import Optional, List
9
 
10
+ os.environ["GRADIO_SSR_MODE"] = "false"
 
11
 
12
  import torch
13
  from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
14
  import spaces
15
+ from gradio import Server
16
+ from fastapi import Security, HTTPException, Depends
17
  from fastapi.security import APIKeyHeader, HTTPBasic, HTTPBasicCredentials
18
  from fastapi.middleware.cors import CORSMiddleware
19
  from fastapi.responses import HTMLResponse
 
21
 
22
  import agent_core as AC
23
 
24
+ logging.basicConfig(level=logging.INFO, format="%(asctime)s | %(message)s")
25
+ logger = logging.getLogger("SaaS-API")
26
+
27
  ADMIN_USER = os.environ.get("ADMIN_USER")
28
  ADMIN_PASS = os.environ.get("ADMIN_PASS")
29
  DB_FILE = "database.json"
 
125
  max_steps: int = 12
126
 
127
  # ================= APP =================
128
+ # PENTING: Gunakan gradio.Server, BUKAN FastAPI langsung.
129
+ # gradio.Server adalah subclass dari FastAPI, jadi semua route/middleware tetap jalan.
130
+ # Ini WAJIB agar harness ZeroGPU Hugging Face bisa mendeteksi @spaces.GPU saat startup.
131
+ app = Server(title="Private AI")
132
  app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])
133
 
134
  api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False)
 
323
  </script></body></html>"""
324
 
325
  if __name__ == "__main__":
326
+ # PENTING: app.launch() memicu hook ZeroGPU HF agar proxy aktif.
327
+ app.launch(show_error=True)