Alnabilali1 commited on
Commit
7107219
·
verified ·
1 Parent(s): d8ce93e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ # ضع هنا رابط ngrok الذي يخرج لك من Google Colab
5
+ API_URL = "https://c9147e329066.ngrok-free.app"
6
+
7
+ def ask_model(user_input):
8
+ try:
9
+ response = requests.post(API_URL, json={"prompt": user_input})
10
+ if response.status_code == 200:
11
+ return response.json().get("reply", "")
12
+ else:
13
+ return f"❌ خطأ من الخادم: {response.status_code}"
14
+ except Exception as e:
15
+ return f"⚠️ تعذر الاتصال بالخادم: {e}"
16
+
17
+ with gr.Blocks() as demo:
18
+ gr.Markdown("# 🤖 Alnabil AI Chatbot")
19
+ gr.Markdown("تحدث مع موديل النبيل مباشرة عبر Google Colab API")
20
+
21
+ with gr.Row():
22
+ with gr.Column(scale=4):
23
+ chatbot = gr.Chatbot()
24
+ msg = gr.Textbox(placeholder="اكتب رسالتك هنا...")
25
+ with gr.Column(scale=1):
26
+ send_btn = gr.Button("إرسال")
27
+
28
+ def respond(message, chat_history):
29
+ bot_reply = ask_model(message)
30
+ chat_history.append((message, bot_reply))
31
+ return "", chat_history
32
+
33
+ send_btn.click(respond, [msg, chatbot], [msg, chatbot])
34
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
35
+
36
+ demo.launch()