Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
from llama_cpp import Llama
|
| 4 |
|
| 5 |
-
# ১.
|
| 6 |
-
print("⏳ মডেল
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 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
|
| 22 |
|
| 23 |
# ৩. স্ট্রিমিং জেনারেশন
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 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
|
| 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()
|