my-script-token / app.py
Alnabilali1's picture
Update app.py
d97065e verified
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()