Hadeeratef91 commited on
Commit
07efe6a
·
verified ·
1 Parent(s): 3f875fc

Update interface.py

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