saiful-ai-dev commited on
Commit
88fc974
·
verified ·
1 Parent(s): d3b45f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -7
app.py CHANGED
@@ -1,22 +1,39 @@
1
  import gradio as gr
2
  from huggingface_hub import hf_hub_download
3
  from llama_cpp import Llama
 
4
 
5
- # তোমার নিজের রিপো থেকে GGUF মডেল লোড
 
6
  model_path = hf_hub_download(
7
  repo_id="saiful-ai-dev/MotionMindX",
8
  filename="Qwen2.5-3B-Instruct-Q4_K_M.gguf"
9
  )
10
 
11
- # মডেল সেটআপ (threads বাড়িয়ে দিলাম স্পিড পাওয়ার জন্য)
12
- llm = Llama(model_path=model_path, n_ctx=2048, n_threads=2)
 
 
 
 
 
 
13
 
14
  def respond(message, history):
15
- prompt = f"<|im_start|>system\nYou are Motion Mind X, a helpful tutor.<|im_end|>\n<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
16
- response = llm(prompt, max_tokens=512, stop=["<|im_end|>"], echo=False)
 
 
 
 
 
 
 
 
17
  return response['choices'][0]['text']
18
 
19
- demo = gr.ChatInterface(respond, title="Motion Mind X 🚀 (GGUF Mode)")
 
20
 
21
  if __name__ == "__main__":
22
- demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import hf_hub_download
3
  from llama_cpp import Llama
4
+ import os
5
 
6
+ # ১. মডেল ডাউনলোড
7
+ print("⏳ মডেল ডাউনলোড হচ্ছে...")
8
  model_path = hf_hub_download(
9
  repo_id="saiful-ai-dev/MotionMindX",
10
  filename="Qwen2.5-3B-Instruct-Q4_K_M.gguf"
11
  )
12
 
13
+ # ২. মডেল সেটআপ (অল্প র‍্যাম ব্যবহারের জন্য সেটিংস)
14
+ print("🚀 মডেল মেমরিতে লোড হচ্ছে...")
15
+ llm = Llama(
16
+ model_path=model_path,
17
+ n_ctx=1024, # কনটেক্সট উইন্ডো কিছুটা কমালাম যাতে ক্রাশ না করে
18
+ n_threads=2, # ফ্রি সিপিপিইউ-র জন্য ২ থ্রেড পারফেক্ট
19
+ n_gpu_layers=0 # যেহেতু আমাদের জিপিইউ নেই
20
+ )
21
 
22
  def respond(message, history):
23
+ # প্রম্পট ফরম্যাট
24
+ prompt = f"<|im_start|>system\nYou are Motion Mind X, a friendly SSC/HSC tutor from Bangladesh. Respond in Bengali or English as appropriate.<|im_end|>\n<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
25
+
26
+ # জেনারেশন
27
+ response = llm(
28
+ prompt,
29
+ max_tokens=256,
30
+ stop=["<|im_end|>", "user:", "assistant:"],
31
+ echo=False
32
+ )
33
  return response['choices'][0]['text']
34
 
35
+ # ৩. ইন্টারফেস লঞ্চ
36
+ demo = gr.ChatInterface(respond, title="Motion Mind X 🚀")
37
 
38
  if __name__ == "__main__":
39
+ demo.launch(server_name="0.0.0.0", server_port=7860)