| import gradio as gr |
| from huggingface_hub import hf_hub_download |
| from llama_cpp import Llama |
|
|
| |
| print("⏳ جاري تحميل النموذج من المستودع...") |
| model_path = hf_hub_download( |
| repo_id="Bilalshai/UnivCh-GGUF", |
| filename="UnivCh-Llama3.1-8B-Q4_K_M.gguf" |
| ) |
| print(f"✅ تم تنزيل النموذج: {model_path}") |
|
|
| |
| print("🧠 جاري تحميل النموذج في الذاكرة...") |
| llm = Llama( |
| model_path=model_path, |
| n_ctx=2048, |
| n_threads=8 |
| ) |
| print("🎉 النموذج جاهز!") |
|
|
| |
| def chat_fn(message, history=[]): |
| prompt = "" |
| for user_msg, bot_msg in history: |
| prompt += f"User: {user_msg}\nAssistant: {bot_msg}\n" |
| prompt += f"User: {message}\nAssistant:" |
|
|
| response = llm(prompt, max_tokens=512, stop=["User:", "Assistant:"]) |
| answer = response["choices"][0]["text"].strip() |
| history.append((message, answer)) |
| return history, history |
|
|
| |
| iface = gr.ChatInterface( |
| fn=chat_fn, |
| title="🤖 UnivCh Chatbot", |
| description="دردشة مع نموذج UnivCh-Llama3.1-8B من Hugging Face Repo" |
| ) |
|
|
| if __name__ == "__main__": |
| iface.launch() |
|
|