Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,9 @@ import json
|
|
| 8 |
# ===============================
|
| 9 |
MODEL_NAME = os.environ.get("MODEL_NAME", "kawkabelaloom/astramind")
|
| 10 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
headers = {
|
| 14 |
"Authorization": f"Bearer {HF_TOKEN}",
|
|
@@ -28,13 +30,11 @@ class AstramindChatbot:
|
|
| 28 |
|
| 29 |
def build_prompt(self, user_message):
|
| 30 |
prompt = self.system_prompt
|
| 31 |
-
|
| 32 |
for msg in self.history[-6:]:
|
| 33 |
if msg["role"] == "user":
|
| 34 |
prompt += f"المستخدم: {msg['content']}\n"
|
| 35 |
else:
|
| 36 |
prompt += f"المساعد: {msg['content']}\n"
|
| 37 |
-
|
| 38 |
prompt += f"المستخدم: {user_message}\nالمساعد:"
|
| 39 |
return prompt
|
| 40 |
|
|
@@ -53,7 +53,7 @@ class AstramindChatbot:
|
|
| 53 |
}
|
| 54 |
}
|
| 55 |
|
| 56 |
-
print("\n📤 PROMPT
|
| 57 |
print("\n📤 PAYLOAD:\n", json.dumps(payload, ensure_ascii=False, indent=2))
|
| 58 |
|
| 59 |
response = requests.post(
|
|
@@ -115,7 +115,6 @@ with gr.Blocks(title="Astramind") as demo:
|
|
| 115 |
gr.Markdown("# 🤖 Astramind Chatbot")
|
| 116 |
|
| 117 |
status = gr.Textbox("جاهز", interactive=False)
|
| 118 |
-
|
| 119 |
chat_ui = gr.Chatbot(height=400)
|
| 120 |
|
| 121 |
with gr.Row():
|
|
@@ -128,7 +127,6 @@ with gr.Blocks(title="Astramind") as demo:
|
|
| 128 |
|
| 129 |
send.click(respond, [msg, chat_ui, tokens, temp], [chat_ui, msg, status])
|
| 130 |
msg.submit(respond, [msg, chat_ui, tokens, temp], [chat_ui, msg, status])
|
| 131 |
-
|
| 132 |
gr.Button("مسح").click(clear, outputs=[chat_ui, status])
|
| 133 |
|
| 134 |
demo.launch(server_name="0.0.0.0", server_port=7860, debug=True)
|
|
|
|
| 8 |
# ===============================
|
| 9 |
MODEL_NAME = os.environ.get("MODEL_NAME", "kawkabelaloom/astramind")
|
| 10 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 11 |
+
|
| 12 |
+
# ⬅️ الحل هنا
|
| 13 |
+
API_URL = f"https://api-inference.huggingface.co/models/{MODEL_NAME}?task=text-generation"
|
| 14 |
|
| 15 |
headers = {
|
| 16 |
"Authorization": f"Bearer {HF_TOKEN}",
|
|
|
|
| 30 |
|
| 31 |
def build_prompt(self, user_message):
|
| 32 |
prompt = self.system_prompt
|
|
|
|
| 33 |
for msg in self.history[-6:]:
|
| 34 |
if msg["role"] == "user":
|
| 35 |
prompt += f"المستخدم: {msg['content']}\n"
|
| 36 |
else:
|
| 37 |
prompt += f"المساعد: {msg['content']}\n"
|
|
|
|
| 38 |
prompt += f"المستخدم: {user_message}\nالمساعد:"
|
| 39 |
return prompt
|
| 40 |
|
|
|
|
| 53 |
}
|
| 54 |
}
|
| 55 |
|
| 56 |
+
print("\n📤 PROMPT:\n", prompt)
|
| 57 |
print("\n📤 PAYLOAD:\n", json.dumps(payload, ensure_ascii=False, indent=2))
|
| 58 |
|
| 59 |
response = requests.post(
|
|
|
|
| 115 |
gr.Markdown("# 🤖 Astramind Chatbot")
|
| 116 |
|
| 117 |
status = gr.Textbox("جاهز", interactive=False)
|
|
|
|
| 118 |
chat_ui = gr.Chatbot(height=400)
|
| 119 |
|
| 120 |
with gr.Row():
|
|
|
|
| 127 |
|
| 128 |
send.click(respond, [msg, chat_ui, tokens, temp], [chat_ui, msg, status])
|
| 129 |
msg.submit(respond, [msg, chat_ui, tokens, temp], [chat_ui, msg, status])
|
|
|
|
| 130 |
gr.Button("مسح").click(clear, outputs=[chat_ui, status])
|
| 131 |
|
| 132 |
demo.launch(server_name="0.0.0.0", server_port=7860, debug=True)
|