Spaces:
Sleeping
Sleeping
mostafasmart
commited on
Commit
•
5eabb89
1
Parent(s):
fca99fd
add app.py1
Browse files- app.py +39 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pusher
|
3 |
+
import json
|
4 |
+
|
5 |
+
# تهيئة Pusher مرة واحدة
|
6 |
+
pusher_client = pusher.Pusher(
|
7 |
+
app_id='1853840',
|
8 |
+
key= 'a1a5cbeadb52b107ea69' ,
|
9 |
+
secret='29b058c83b90d893cfbb',
|
10 |
+
cluster='eu',
|
11 |
+
ssl=True
|
12 |
+
)
|
13 |
+
|
14 |
+
# الدالة التي تستقبل الرسالة وترسلها إلى Pusher
|
15 |
+
def predict(message_json):
|
16 |
+
# تحويل المدخلات إلى JSON
|
17 |
+
try:
|
18 |
+
message = json.loads(message_json)
|
19 |
+
|
20 |
+
# استخدام Pusher لإرسال الرسالة
|
21 |
+
pusher_client.trigger(f'conversation-{message["conversation_id"]}', 'new-message', {
|
22 |
+
'message': message
|
23 |
+
})
|
24 |
+
|
25 |
+
return "تم إرسال الرسالة بنجاح إلى Pusher!"
|
26 |
+
except Exception as e:
|
27 |
+
return f"حدث خطأ: {str(e)}"
|
28 |
+
|
29 |
+
# إعداد واجهة Gradio
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=predict,
|
32 |
+
inputs=gr.Textbox(lines=10, placeholder="أدخل رسالة JSON هنا...", label="Message JSON"),
|
33 |
+
outputs="text",
|
34 |
+
title="Real-time Message Sender",
|
35 |
+
description="واجهة لاستقبال رسالة JSON وإرسالها عبر Pusher"
|
36 |
+
)
|
37 |
+
|
38 |
+
# تشغيل الواجهة
|
39 |
+
iface.launch(share=True)
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
Pillow
|
3 |
+
requests
|
4 |
+
numpy
|
5 |
+
transformers==4.44.2
|
6 |
+
pusher==3.3.2
|