saiful-ai-dev commited on
Commit
730c866
·
verified ·
1 Parent(s): f33d52c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -31
app.py CHANGED
@@ -1,42 +1,27 @@
1
  import gradio as gr
2
- from huggingface_hub import hf_hub_download
3
- from llama_cpp import Llama
4
 
5
- # ১. তোার GGUF মডেল ডাউনলোড
6
- print("⏳ মডেল ডাউনলোড হচ্ছে...")
7
- model_path = hf_hub_download(
8
- repo_id="saiful-ai-dev/MotionMindX",
9
- filename="Qwen2.5-3B-Instruct-Q4_K_M.gguf"
10
- )
11
-
12
- # ২. মডেল সেটআপ (২০৪৮ কনটেক্সট)
13
- llm = Llama(
14
- model_path=model_path,
15
- n_ctx=2048,
16
- n_threads=2
17
  )
18
 
19
  def respond(message, history):
20
- # ট্িিং ফরমযা
21
- prompt = f"<|im_start|>system\nYou are Motion Mind X, a helpful tutor for SSC/HSC students in Bangladesh.<|im_end|>\n<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
22
 
23
  # ৩. স্ট্রিমিং জেনারেশন
24
- response_stream = llm(
25
- prompt,
26
- max_tokens=1024,
27
- stop=["<|im_end|>"],
28
- stream=True
29
- )
30
-
31
- partial_message = ""
32
- for chunk in response_stream:
33
- if "text" in chunk["choices"][0]:
34
- token = chunk["choices"][0]["text"]
35
- partial_message += token
36
- yield partial_message # টাইপ রাইটারের মতো লেখা দেখাবে
37
 
38
  # ৪. ইন্টারফেস
39
- demo = gr.ChatInterface(respond, title="Motion Mind X 🚀 (GGUF Streaming)")
40
 
41
  if __name__ == "__main__":
42
- demo.launch()
 
1
  import gradio as gr
2
+ from ctransformers import AutoModelForCausalLM
 
3
 
4
+ # ১. মডেল লোড (সরাসরি GGUF সাপোর্ট করে)
5
+ print("⏳ মডেল লোড হচ্ছে... এটি ২-৩ মিনিট সময় নিতে পারে।")
6
+ llm = AutoModelForCausalLM.from_pretrained(
7
+ "saiful-ai-dev/MotionMindX",
8
+ model_file="Qwen2.5-3B-Instruct-Q4_K_M.gguf",
9
+ model_type="gpt2", # কিউওয়েন মডেলের জন্য এটি প্রক্সি হিসেবে কাজ করে
10
+ context_length=2048
 
 
 
 
 
11
  )
12
 
13
  def respond(message, history):
14
+ # ২. প্রম্ তৈরি
15
+ prompt = f"<|im_start|>system\nYou are Motion Mind X, a helpful tutor from Bangladesh.<|im_end|>\n<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
16
 
17
  # ৩. স্ট্রিমিং জেনারেশন
18
+ response_text = ""
19
+ for token in llm(prompt, stream=True, max_new_tokens=512, stop=["<|im_end|>"]):
20
+ response_text += token
21
+ yield response_text
 
 
 
 
 
 
 
 
 
22
 
23
  # ৪. ইন্টারফেস
24
+ demo = gr.ChatInterface(respond, title="Motion Mind X 🚀 (GGUF Mode)")
25
 
26
  if __name__ == "__main__":
27
+ demo.launch()