Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,46 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
)
|
| 17 |
|
| 18 |
def respond(message, history):
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
#
|
| 29 |
demo = gr.ChatInterface(
|
| 30 |
respond,
|
| 31 |
title="Motion Mind X 🚀",
|
| 32 |
-
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
from llama_cpp import Llama
|
| 4 |
|
| 5 |
+
# ১. মডেল ডাউনলোড
|
| 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 |
+
# ২. মডেল সেটিংস (তোমার চাওয়া অনুযায়ী ২০৪৮ সেট করা হয়েছে)
|
| 12 |
+
llm = Llama(
|
| 13 |
+
model_path=model_path,
|
| 14 |
+
n_ctx=2048, # Context window
|
| 15 |
+
n_batch=512, # RAM বাঁচাতে ব্যাচ সাইজ একটু কম রাখা ভালো, তবে প্রম্পট ২০৪৮ হ্যান্ডেল করবে
|
| 16 |
+
n_threads=2 # Free CPU এর জন্য এটাই সেরা
|
| 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. Respond clearly.<|im_end|>\n<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
|
| 22 |
+
|
| 23 |
+
# ৩. স্ট্রিমিং (Streaming) শুরু
|
| 24 |
+
response_stream = llm(
|
| 25 |
+
prompt,
|
| 26 |
+
max_tokens=512,
|
| 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(
|
| 40 |
respond,
|
| 41 |
title="Motion Mind X 🚀",
|
| 42 |
+
description="SSC/HSC শিক্ষার্থীদের জন্য লাইভ এআই টিউটর (Streaming Enabled)",
|
| 43 |
+
theme="soft"
|
| 44 |
)
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|