Spaces:
Sleeping
Sleeping
File size: 1,035 Bytes
7107219 d97065e 7107219 d97065e 7107219 d97065e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import gradio as gr
import requests
# ضع هنا رابط ngrok الذي ظهر في Google Colab
API_URL = "https://c9147e329066.ngrok-free.app/chat"
def ask_model(user_input):
try:
response = requests.post(API_URL, json={"prompt": user_input})
if response.status_code == 200:
return response.json().get("reply", "")
else:
return f"❌ خطأ من الخادم: {response.status_code}"
except Exception as e:
return f"⚠️ تعذر الاتصال بالخادم: {e}"
with gr.Blocks() as demo:
gr.Markdown("# 🤖 Alnabil AI Chatbot")
gr.Markdown("تحدث مع موديل النبيل مباشرة عبر Google Colab API")
chatbot = gr.Chatbot()
msg = gr.Textbox(placeholder="اكتب رسالتك هنا...")
def respond(message, chat_history):
bot_reply = ask_model(message)
chat_history.append((message, bot_reply))
return "", chat_history
msg.submit(respond, [msg, chatbot], [msg, chatbot])
demo.launch()
|