Update app.py
Browse files
app.py
CHANGED
|
@@ -4,12 +4,13 @@ from pydantic import BaseModel
|
|
| 4 |
import torch
|
| 5 |
import re
|
| 6 |
import secrets
|
| 7 |
-
import requests
|
| 8 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 9 |
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
CORSMiddleware,
|
| 14 |
allow_origins=["*"],
|
| 15 |
allow_methods=["*"],
|
|
@@ -24,18 +25,20 @@ API_KEYS_DB = {
|
|
| 24 |
ADMIN_SECRET = "MINZO-SECRET-2026"
|
| 25 |
|
| 26 |
# ββ Google Search Config ββ
|
|
|
|
| 27 |
GOOGLE_API_KEY = "YOUR_GOOGLE_API_KEY"
|
| 28 |
GOOGLE_CX = "YOUR_CUSTOM_SEARCH_ENGINE_ID"
|
| 29 |
|
| 30 |
# ββ Load AI Model for CPU ββ
|
| 31 |
-
model_id = "google/gemma-
|
| 32 |
print(f"Loading {model_id} on CPU (Optimized for 18GB RAM)...")
|
| 33 |
|
| 34 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 35 |
-
|
|
|
|
| 36 |
model = AutoModelForCausalLM.from_pretrained(
|
| 37 |
model_id,
|
| 38 |
-
|
| 39 |
device_map="cpu",
|
| 40 |
trust_remote_code=True
|
| 41 |
)
|
|
@@ -96,7 +99,7 @@ def should_search(query: str) -> bool:
|
|
| 96 |
# ββββββββββββββββββββββββββββββββββββββ
|
| 97 |
# ENDPOINTS
|
| 98 |
# ββββββββββββββββββββββββββββββββββββββ
|
| 99 |
-
@
|
| 100 |
def home():
|
| 101 |
return {
|
| 102 |
"status": "Inachi-Core Active",
|
|
@@ -104,7 +107,7 @@ def home():
|
|
| 104 |
"search": "Google Real-time",
|
| 105 |
}
|
| 106 |
|
| 107 |
-
@
|
| 108 |
async def generate_key(data: AdminRequest):
|
| 109 |
if data.admin_pass != ADMIN_SECRET:
|
| 110 |
raise HTTPException(status_code=401, detail="Unauthorized Access!")
|
|
@@ -112,7 +115,7 @@ async def generate_key(data: AdminRequest):
|
|
| 112 |
API_KEYS_DB[new_key] = {"limit": data.limit, "used": 0, "status": "active"}
|
| 113 |
return {"api_key": new_key, "limit": data.limit}
|
| 114 |
|
| 115 |
-
@
|
| 116 |
async def chat(message: ChatRequest, x_api_key: str = Header(None)):
|
| 117 |
if not x_api_key or x_api_key not in API_KEYS_DB:
|
| 118 |
raise HTTPException(status_code=403, detail="Access Denied")
|
|
|
|
| 4 |
import torch
|
| 5 |
import re
|
| 6 |
import secrets
|
| 7 |
+
import requests
|
| 8 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 9 |
|
| 10 |
+
# Hugging Face ΰ·ΰΆ»ΰ·ΰ·ΰΆ»ΰ· ΰΆΰΆ 'main' ΰΆ½ΰ·ΰΆ©ΰ· ΰΆΰ·ΰΆ»ΰ·ΰΆΈΰΆ§ ΰΆΰΆΰ·ΰ·ΰ·ΰ· ΰΆΰΆ»ΰΆ± ΰΆΆΰ·ΰ·ΰ·ΰΆ±ΰ· ΰΆΈΰ·ΰΆΊ ΰΆΈΰ·ΰ·ΰ· ΰΆ±ΰΆΈΰ· ΰΆΰΆ»ΰΆ± ΰΆ½ΰΆ―ΰ·.
|
| 11 |
+
main = FastAPI()
|
| 12 |
|
| 13 |
+
main.add_middleware(
|
| 14 |
CORSMiddleware,
|
| 15 |
allow_origins=["*"],
|
| 16 |
allow_methods=["*"],
|
|
|
|
| 25 |
ADMIN_SECRET = "MINZO-SECRET-2026"
|
| 26 |
|
| 27 |
# ββ Google Search Config ββ
|
| 28 |
+
# MINZO-PRIME, ΰΆΰΆΊΰ·ΰΆΰ· Keys ΰΆΈΰ·ΰΆΰΆ±ΰΆ§ ΰΆΰΆΰ·ΰ·
ΰΆΰ· ΰΆΰΆ»ΰΆ±ΰ·ΰΆ±.
|
| 29 |
GOOGLE_API_KEY = "YOUR_GOOGLE_API_KEY"
|
| 30 |
GOOGLE_CX = "YOUR_CUSTOM_SEARCH_ENGINE_ID"
|
| 31 |
|
| 32 |
# ββ Load AI Model for CPU ββ
|
| 33 |
+
model_id = "google/gemma-2-9b-it"
|
| 34 |
print(f"Loading {model_id} on CPU (Optimized for 18GB RAM)...")
|
| 35 |
|
| 36 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 37 |
+
|
| 38 |
+
# 'torch_dtype' ΰ·ΰ·ΰΆ±ΰ·ΰ·ΰΆ§ ΰΆ
ΰΆ½ΰ·ΰΆΰ· 'dtype' ΰΆ΄ΰΆ»ΰ·ΰΆΈΰ·ΰΆΰ·ΰΆΊ ΰΆ·ΰ·ΰ·ΰ·ΰΆΰ· ΰΆΰΆ» ΰΆΰΆ.
|
| 39 |
model = AutoModelForCausalLM.from_pretrained(
|
| 40 |
model_id,
|
| 41 |
+
dtype=torch.bfloat16,
|
| 42 |
device_map="cpu",
|
| 43 |
trust_remote_code=True
|
| 44 |
)
|
|
|
|
| 99 |
# ββββββββββββββββββββββββββββββββββββββ
|
| 100 |
# ENDPOINTS
|
| 101 |
# ββββββββββββββββββββββββββββββββββββββ
|
| 102 |
+
@main.get("/")
|
| 103 |
def home():
|
| 104 |
return {
|
| 105 |
"status": "Inachi-Core Active",
|
|
|
|
| 107 |
"search": "Google Real-time",
|
| 108 |
}
|
| 109 |
|
| 110 |
+
@main.post("/v1/generate-key")
|
| 111 |
async def generate_key(data: AdminRequest):
|
| 112 |
if data.admin_pass != ADMIN_SECRET:
|
| 113 |
raise HTTPException(status_code=401, detail="Unauthorized Access!")
|
|
|
|
| 115 |
API_KEYS_DB[new_key] = {"limit": data.limit, "used": 0, "status": "active"}
|
| 116 |
return {"api_key": new_key, "limit": data.limit}
|
| 117 |
|
| 118 |
+
@main.post("/v1/chat")
|
| 119 |
async def chat(message: ChatRequest, x_api_key: str = Header(None)):
|
| 120 |
if not x_api_key or x_api_key not in API_KEYS_DB:
|
| 121 |
raise HTTPException(status_code=403, detail="Access Denied")
|