Update app.py
Browse files
app.py
CHANGED
|
@@ -4,55 +4,38 @@ from huggingface_hub import InferenceClient
|
|
| 4 |
# استدعاء الموديل
|
| 5 |
client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 6 |
|
| 7 |
-
def respond(message, history):
|
| 8 |
-
# نظام التعليمات
|
| 9 |
-
system_message = "أنت CODEK، أقوى أيجنت ذكاء اصطناعي. تحدث بالعربية
|
| 10 |
|
| 11 |
-
# تجهيز الرسائل
|
| 12 |
messages = [{"role": "system", "content": system_message}]
|
| 13 |
-
|
| 14 |
-
#
|
| 15 |
-
for
|
| 16 |
-
|
| 17 |
-
if ai_msg: messages.append({"role": "assistant", "content": ai_msg})
|
| 18 |
|
| 19 |
messages.append({"role": "user", "content": message})
|
| 20 |
|
| 21 |
response = ""
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
custom_css = """
|
| 33 |
-
footer {visibility: hidden}
|
| 34 |
-
.gradio-container { background-color: #020617 !important; }
|
| 35 |
-
h1 { color: #3b82f6 !important; text-shadow: 0 0 15px #3b82f6; font-family: 'Arial', sans-serif; text-align: center; padding: 20px; }
|
| 36 |
-
.message.user { background-color: #1e293b !important; border: 1px solid #3b82f6 !important; }
|
| 37 |
-
.message.assistant { background-color: #0f172a !important; border: 1px solid #9333ea !important; }
|
| 38 |
-
"""
|
| 39 |
|
| 40 |
# بناء الواجهة
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
chat_history.append((message, ""))
|
| 52 |
-
for response in bot_generator:
|
| 53 |
-
chat_history[-1] = (message, response)
|
| 54 |
-
yield "", chat_history
|
| 55 |
-
|
| 56 |
-
msg.submit(chat_action, [msg, chatbot], [msg, chatbot])
|
| 57 |
-
|
| 58 |
-
demo.launch()
|
|
|
|
| 4 |
# استدعاء الموديل
|
| 5 |
client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 6 |
|
| 7 |
+
def respond(message, history: list[dict]):
|
| 8 |
+
# نظام التعليمات
|
| 9 |
+
system_message = "أنت CODEK، أقوى أيجنت ذكاء اصطناعي. تحدث بالعربية واكتب أكواد احترافية."
|
| 10 |
|
|
|
|
| 11 |
messages = [{"role": "system", "content": system_message}]
|
| 12 |
+
|
| 13 |
+
# إضافة التاريخ (History) بطريقة متوافقة مع التحديث الجديد
|
| 14 |
+
for msg in history:
|
| 15 |
+
messages.append(msg)
|
|
|
|
| 16 |
|
| 17 |
messages.append({"role": "user", "content": message})
|
| 18 |
|
| 19 |
response = ""
|
| 20 |
+
# جلب الرد
|
| 21 |
+
for message_chunk in client.chat_completion(
|
| 22 |
+
messages,
|
| 23 |
+
max_tokens=2048,
|
| 24 |
+
stream=True,
|
| 25 |
+
):
|
| 26 |
+
token = message_chunk.choices[0].delta.content
|
| 27 |
+
if token:
|
| 28 |
+
response += token
|
| 29 |
+
yield response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# بناء الواجهة
|
| 32 |
+
demo = gr.ChatInterface(
|
| 33 |
+
fn=respond,
|
| 34 |
+
type="messages", # ده المهم جداً للتحديث الجديد
|
| 35 |
+
title="⚡ CODEK ULTIMATE AGENT",
|
| 36 |
+
description="اسأل كودك عن أي كود برمجى أو مشروع ضخم",
|
| 37 |
+
theme="ocean" # ثيم هادي وشيك لحد ما نضمن التشغيل
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|