Spaces:
Sleeping
Sleeping
Commit
·
31ceb6e
1
Parent(s):
6dd1e7c
add app.py3
Browse files
app.py
CHANGED
@@ -11,11 +11,29 @@ pusher_client = pusher.Pusher(
|
|
11 |
ssl=True
|
12 |
)
|
13 |
|
14 |
-
# الدالة التي تستقبل الرسالة وترسلها إلى Pusher
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def predict(message_json):
|
16 |
-
# تحويل المدخلات إلى JSON
|
17 |
try:
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# استخدام Pusher لإرسال الرسالة
|
21 |
pusher_client.trigger(f'conversation-{message["conversation_id"]}', 'new-message', {
|
@@ -24,8 +42,7 @@ def predict(message_json):
|
|
24 |
|
25 |
return "تم إرسال الرسالة بنجاح إلى Pusher!"
|
26 |
except Exception as e:
|
27 |
-
return f"{
|
28 |
-
|
29 |
# إعداد واجهة Gradio
|
30 |
iface = gr.Interface(
|
31 |
fn=predict,
|
|
|
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"{message_json}"
|
28 |
+
|
29 |
+
|
30 |
def predict(message_json):
|
|
|
31 |
try:
|
32 |
+
# استخراج الرسالة كـ string من القائمة
|
33 |
+
message_str = message_json[0] # الحصول على العنصر الأول من القائمة
|
34 |
+
|
35 |
+
# تحويل الـ string إلى كائن JSON
|
36 |
+
message = json.loads(message_str.replace("'", '"')) # استبدال ' بـ " لجعل JSON صالحًا
|
37 |
|
38 |
# استخدام Pusher لإرسال الرسالة
|
39 |
pusher_client.trigger(f'conversation-{message["conversation_id"]}', 'new-message', {
|
|
|
42 |
|
43 |
return "تم إرسال الرسالة بنجاح إلى Pusher!"
|
44 |
except Exception as e:
|
45 |
+
return f"حدث خطأ: {str(e)}"
|
|
|
46 |
# إعداد واجهة Gradio
|
47 |
iface = gr.Interface(
|
48 |
fn=predict,
|