MINZO4546 commited on
Commit
27cf60a
·
verified ·
1 Parent(s): d76d7d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -6,7 +6,7 @@ import torch
6
 
7
  main = FastAPI()
8
 
9
- # CORS සක්‍රීය කිරීම - ඕනෑම තැනක සිට සම්බන්ධ වීමට
10
  main.add_middleware(
11
  CORSMiddleware,
12
  allow_origins=["*"],
@@ -15,14 +15,14 @@ main.add_middleware(
15
  )
16
 
17
  MODEL_ID = "tencent/Hy-MT1.5-1.8B-2bit"
18
- print(f"🔱 Specialist, Loading {MODEL_ID} (Public Mode)...")
19
 
20
- # Pipeline initialization
21
  pipe = pipeline(
22
  "text-generation",
23
  model=MODEL_ID,
24
  device_map="cpu",
25
- model_kwargs={"trust_remote_code": True}
26
  )
27
 
28
  class ChatRequest(BaseModel):
@@ -32,10 +32,10 @@ class ChatRequest(BaseModel):
32
  async def chat(request_data: ChatRequest):
33
  user_query = request_data.message.strip()
34
 
35
- # Prompt Setup
36
  prompt = f"User: {user_query}\nAssistant:"
37
 
38
- # Text Generation
39
  results = pipe(
40
  prompt,
41
  max_new_tokens=150,
@@ -46,13 +46,14 @@ async def chat(request_data: ChatRequest):
46
 
47
  # Result Cleaning
48
  generated_text = results[0]['generated_text']
49
- reply = generated_text.split("Assistant:")[-1].strip()
50
-
51
- if not reply:
52
- reply = "I am here, MINZO-PRIME. Systems are nominal."
 
53
 
54
  return {"reply": reply}
55
 
56
  @main.get("/")
57
  def health():
58
- return {"status": "Public Inachi-Lite Online"}
 
6
 
7
  main = FastAPI()
8
 
9
+ # CORS සක්‍රීය කිරීම
10
  main.add_middleware(
11
  CORSMiddleware,
12
  allow_origins=["*"],
 
15
  )
16
 
17
  MODEL_ID = "tencent/Hy-MT1.5-1.8B-2bit"
18
+ print(f"🔱 Specialist, Loading {MODEL_ID} on CPU...")
19
 
20
+ # 🔱 Pipeline එක නිවැරදිව load කිරීම
21
  pipe = pipeline(
22
  "text-generation",
23
  model=MODEL_ID,
24
  device_map="cpu",
25
+ trust_remote_code=True # කෙලින්ම මෙතනට පමණක් ලබා දෙන්න
26
  )
27
 
28
  class ChatRequest(BaseModel):
 
32
  async def chat(request_data: ChatRequest):
33
  user_query = request_data.message.strip()
34
 
35
+ # Simple Prompt
36
  prompt = f"User: {user_query}\nAssistant:"
37
 
38
+ # Response Generation
39
  results = pipe(
40
  prompt,
41
  max_new_tokens=150,
 
46
 
47
  # Result Cleaning
48
  generated_text = results[0]['generated_text']
49
+ # Assistant: කියන කොටසෙන් පස්සේ තියෙන ටික විතරක් ගැනීම
50
+ if "Assistant:" in generated_text:
51
+ reply = generated_text.split("Assistant:")[-1].strip()
52
+ else:
53
+ reply = generated_text.replace(prompt, "").strip()
54
 
55
  return {"reply": reply}
56
 
57
  @main.get("/")
58
  def health():
59
+ return {"status": "Inachi-Lite Online", "model": MODEL_ID}