Hadeeratef91 commited on
Commit
59b3651
·
verified ·
1 Parent(s): 50086fc

Update interface.py

Browse files
Files changed (1) hide show
  1. interface.py +71 -71
interface.py CHANGED
@@ -1,71 +1,71 @@
1
- import gradio as gr
2
- import requests
3
-
4
- API_URL = "https://your-huggingface-space-url.hf.space/complaints/"
5
- STATUS_UPDATE_URL = "https://your-huggingface-space-url.hf.space/complaints/{complaint_id}/status/"
6
- EXPORT_URL = "https://your-huggingface-space-url.hf.space/export/"
7
-
8
- def submit_complaint(title, description):
9
- try:
10
- response = requests.post(API_URL, json={"title": title, "description": description})
11
- response.raise_for_status()
12
- data = response.json()
13
- return data.get("message", "✅ تم إرسال الشكوى بنجاح!")
14
- except requests.exceptions.RequestException as e:
15
- return f"⚠️ خطأ في الاتصال بالخادم: {str(e)}"
16
-
17
- def view_complaints():
18
- try:
19
- response = requests.get(API_URL)
20
- response.raise_for_status()
21
- data = response.json()
22
- if not data:
23
- return "⚠️ لا توجد شكاوى متاحة حتى الآن."
24
- return "\n".join([f"🔹 {item['id']}: {item['title']} ({item['status']}): {item['description']}" for item in data])
25
- except requests.exceptions.RequestException as e:
26
- return f"⚠️ خطأ في جلب الشكاوى: {str(e)}"
27
-
28
- def update_status(complaint_id, new_status):
29
- try:
30
- response = requests.put(STATUS_UPDATE_URL.format(complaint_id=complaint_id), json={"new_status": new_status})
31
- response.raise_for_status()
32
- data = response.json()
33
- return data.get("message", "✅ تم تحديث حالة الشكوى!")
34
- except requests.exceptions.RequestException as e:
35
- return f"⚠️ خطأ في تحديث الشكوى: {str(e)}"
36
-
37
- def export_complaints():
38
- try:
39
- response = requests.get(EXPORT_URL)
40
- response.raise_for_status()
41
- data = response.json()
42
- return data.get("message", "✅ تم تصدير الشكاوى بنجاح!")
43
- except requests.exceptions.RequestException as e:
44
- return f"⚠️ خطأ في تصدير البيانات: {str(e)}"
45
-
46
- demo = gr.Blocks()
47
- with demo:
48
- gr.Markdown("## 🛠️ نظام إدارة الشكاوى")
49
- with gr.Row():
50
- title_input = gr.Textbox(label="عنوان الشكوى")
51
- description_input = gr.Textbox(label="وصف الشكوى")
52
- submit_button = gr.Button("إرسال")
53
- output = gr.Textbox(label="النتيجة")
54
- submit_button.click(submit_complaint, inputs=[title_input, description_input], outputs=output)
55
-
56
- complaints_output = gr.Textbox(label="جميع الشكاوى")
57
- view_button = gr.Button("عرض جميع الشكاوى")
58
- view_button.click(view_complaints, outputs=complaints_output)
59
-
60
- with gr.Row():
61
- complaint_id_input = gr.Textbox(label="رقم الشكوى لتحديث حالتها")
62
- status_input = gr.Dropdown(choices=["Open", "Pending", "Closed"], label="الحالة الجديدة")
63
- update_status_button = gr.Button("تحديث الحالة")
64
- status_output = gr.Textbox(label="نتيجة التحديث")
65
- update_status_button.click(update_status, inputs=[complaint_id_input, status_input], outputs=status_output)
66
-
67
- export_button = gr.Button("تصدير الشكاوى إلى Excel")
68
- export_output = gr.Textbox(label="نتيجة التصدير")
69
- export_button.click(export_complaints, outputs=export_output)
70
-
71
- demo.launch(server_name="0.0.0.0", server_port=None)
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ API_URL = "https://Hadeeratef91/Complaint.hf.space/complaints/"
5
+ STATUS_UPDATE_URL = "https://Hadeeratef91/Complaint.hf.space/complaints/{complaint_id}/status/"
6
+ EXPORT_URL = "https://Hadeeratef91/Complaint.hf.space/export/"
7
+
8
+ def submit_complaint(title, description):
9
+ try:
10
+ response = requests.post(API_URL, json={"title": title, "description": description})
11
+ response.raise_for_status()
12
+ data = response.json()
13
+ return data.get("message", "✅ تم إرسال الشكوى بنجاح!")
14
+ except requests.exceptions.RequestException as e:
15
+ return f"⚠️ خطأ في الاتصال بالخادم: {str(e)}"
16
+
17
+ def view_complaints():
18
+ try:
19
+ response = requests.get(API_URL)
20
+ response.raise_for_status()
21
+ data = response.json()
22
+ if not data:
23
+ return "⚠️ لا توجد شكاوى متاحة حتى الآن."
24
+ return "\n".join([f"🔹 {item['id']}: {item['title']} ({item['status']}): {item['description']}" for item in data])
25
+ except requests.exceptions.RequestException as e:
26
+ return f"⚠️ خطأ في جلب الشكاوى: {str(e)}"
27
+
28
+ def update_status(complaint_id, new_status):
29
+ try:
30
+ response = requests.put(STATUS_UPDATE_URL.format(complaint_id=complaint_id), json={"new_status": new_status})
31
+ response.raise_for_status()
32
+ data = response.json()
33
+ return data.get("message", "✅ تم تحديث حالة الشكوى!")
34
+ except requests.exceptions.RequestException as e:
35
+ return f"⚠️ خطأ في تحديث الشكوى: {str(e)}"
36
+
37
+ def export_complaints():
38
+ try:
39
+ response = requests.get(EXPORT_URL)
40
+ response.raise_for_status()
41
+ data = response.json()
42
+ return data.get("message", "✅ تم تصدير الشكاوى بنجاح!")
43
+ except requests.exceptions.RequestException as e:
44
+ return f"⚠️ خطأ في تصدير البيانات: {str(e)}"
45
+
46
+ demo = gr.Blocks()
47
+ with demo:
48
+ gr.Markdown("## 🛠️ نظام إدارة الشكاوى")
49
+ with gr.Row():
50
+ title_input = gr.Textbox(label="عنوان الشكوى")
51
+ description_input = gr.Textbox(label="وصف الشكوى")
52
+ submit_button = gr.Button("إرسال")
53
+ output = gr.Textbox(label="النتيجة")
54
+ submit_button.click(submit_complaint, inputs=[title_input, description_input], outputs=output)
55
+
56
+ complaints_output = gr.Textbox(label="جميع الشكاوى")
57
+ view_button = gr.Button("عرض جميع الشكاوى")
58
+ view_button.click(view_complaints, outputs=complaints_output)
59
+
60
+ with gr.Row():
61
+ complaint_id_input = gr.Textbox(label="رقم الشكوى لتحديث حالتها")
62
+ status_input = gr.Dropdown(choices=["Open", "Pending", "Closed"], label="الحالة الجديدة")
63
+ update_status_button = gr.Button("تحديث الحالة")
64
+ status_output = gr.Textbox(label="نتيجة التحديث")
65
+ update_status_button.click(update_status, inputs=[complaint_id_input, status_input], outputs=status_output)
66
+
67
+ export_button = gr.Button("تصدير الشكاوى إلى Excel")
68
+ export_output = gr.Textbox(label="نتيجة التصدير")
69
+ export_button.click(export_complaints, outputs=export_output)
70
+
71
+ demo.launch(server_name="0.0.0.0", server_port=None)