MINZO4546 commited on
Commit
749df63
Β·
verified Β·
1 Parent(s): 8f635ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -4,12 +4,13 @@ from pydantic import BaseModel
4
  import torch
5
  import re
6
  import secrets
7
- import requests # Google Search API ΰΆ‘ΰΆšΰΆ§ ΰΆ…ΰ·€ΰ·ΰ·Šβ€ΰΆΊΰΆΊΰ·’
8
  from transformers import AutoModelForCausalLM, AutoTokenizer
9
 
10
- app = FastAPI()
 
11
 
12
- app.add_middleware(
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-4-E4B-it"
32
  print(f"Loading {model_id} on CPU (Optimized for 18GB RAM)...")
33
 
34
  tokenizer = AutoTokenizer.from_pretrained(model_id)
35
- # CPU ΰΆ‘ΰΆšΰ·š ΰΆ―ΰ·”ΰ·€ΰΆ± ࢱිසා torch_dtype ΰΆ‘ΰΆš float16 හෝ bfloat16 ΰΆ―ΰ·ΰΆΈΰ·“ΰΆΈΰ·™ΰΆ±ΰ·Š RAM ΰΆ‘ΰΆš ΰΆ‰ΰΆ­ΰ·’ΰΆ»ΰ·’ ࢚ࢻ࢜ࢭ ΰ·„ΰ·ΰΆš
 
36
  model = AutoModelForCausalLM.from_pretrained(
37
  model_id,
38
- torch_dtype=torch.bfloat16,
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
- @app.get("/")
100
  def home():
101
  return {
102
  "status": "Inachi-Core Active",
@@ -104,7 +107,7 @@ def home():
104
  "search": "Google Real-time",
105
  }
106
 
107
- @app.post("/v1/generate-key")
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
- @app.post("/v1/chat")
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")