saiful-ai-dev commited on
Commit
375f784
·
verified ·
1 Parent(s): b5a9a19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -29
app.py CHANGED
@@ -1,39 +1,36 @@
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)
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+ import torch
 
4
 
5
+ # ৩বি মডেল লোড করার সবথেকে নিরাপদ উপায়
6
+ model_id = "Qwen/Qwen2.5-3B-Instruct"
7
+
8
+ print("⏳ এআই টিউটর লোড হচ্ছে... এটি ২-৩ মিনিট সময় নেবে।")
 
 
9
 
10
+ # মেমোরি বাঁচানোর জন্য বিশেষ সেটিংস
11
+ pipe = pipeline(
12
+ "text-generation",
13
+ model=model_id,
14
+ model_kwargs={"torch_dtype": torch.float32, "low_cpu_mem_usage": True},
15
+ device_map="auto"
 
16
  )
17
 
18
  def respond(message, history):
19
+ messages = [
20
+ {"role": "system", "content": "You are Motion Mind X, a friendly SSC/HSC tutor from Bangladesh. Respond clearly in Bengali/English."},
21
+ {"role": "user", "content": message},
22
+ ]
23
 
24
+ # জেনারেশন শুরু
25
+ out = pipe(messages, max_new_tokens=512)
26
+ return out[0]['generated_text'][-1]['content']
 
 
 
 
 
27
 
28
+ # চ্যাট ইন্টারফেস
29
+ demo = gr.ChatInterface(
30
+ respond,
31
+ title="Motion Mind X 🚀",
32
+ examples=["SSC গণিত প্রস্তুতি কীভাবে নেব?", "HSC English 2nd paper grammar help"]
33
+ )
34
 
35
  if __name__ == "__main__":
36
+ demo.launch()