Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import requests | |
| API_URL = "https://hadeeratef91-complaint.hf.space/complaints/" | |
| STATUS_UPDATE_URL = "https://hadeeratef91-complaint.hf.space/complaints/{complaint_id}/status/" | |
| EXPORT_URL = "https://hadeeratef91-complaint.hf.space/export/" | |
| def submit_complaint(title, description): | |
| try: | |
| response = requests.post(API_URL, json={"title": title, "description": description}) | |
| response.raise_for_status() | |
| data = response.json() | |
| return data.get("message", "✅ تم إرسال الشكوى بنجاح!") | |
| except requests.exceptions.RequestException as e: | |
| return f"⚠️ خطأ في الاتصال بالخادم: {str(e)}" | |
| def view_complaints(): | |
| try: | |
| response = requests.get(API_URL) | |
| response.raise_for_status() | |
| data = response.json() | |
| if not data: | |
| return "⚠️ لا توجد شكاوى متاحة حتى الآن." | |
| return "\n".join([f"🔹 {item['id']}: {item['title']} ({item['status']}): {item['description']}" for item in data]) | |
| except requests.exceptions.RequestException as e: | |
| return f"⚠️ خطأ في جلب الشكاوى: {str(e)}" | |
| def update_status(complaint_id, new_status): | |
| try: | |
| response = requests.put(STATUS_UPDATE_URL.format(complaint_id=complaint_id), json={"new_status": new_status}) | |
| response.raise_for_status() | |
| data = response.json() | |
| return data.get("message", "✅ تم تحديث حالة الشكوى!") | |
| except requests.exceptions.RequestException as e: | |
| return f"⚠️ خطأ في تحديث الشكوى: {str(e)}" | |
| def export_complaints(): | |
| try: | |
| response = requests.get(EXPORT_URL) | |
| response.raise_for_status() | |
| data = response.json() | |
| return data.get("message", "✅ تم تصدير الشكاوى بنجاح!") | |
| except requests.exceptions.RequestException as e: | |
| return f"⚠️ خطأ في تصدير البيانات: {str(e)}" | |
| demo = gr.Blocks() | |
| with demo: | |
| gr.Markdown("## 🛠️ نظام إدارة الشكاوى") | |
| with gr.Row(): | |
| title_input = gr.Textbox(label="عنوان الشكوى") | |
| description_input = gr.Textbox(label="وصف الشكوى") | |
| submit_button = gr.Button("إرسال") | |
| output = gr.Textbox(label="النتيجة") | |
| submit_button.click(submit_complaint, inputs=[title_input, description_input], outputs=output) | |
| complaints_output = gr.Textbox(label="جميع الشكاوى") | |
| view_button = gr.Button("عرض جميع الشكاوى") | |
| view_button.click(view_complaints, outputs=complaints_output) | |
| with gr.Row(): | |
| complaint_id_input = gr.Textbox(label="رقم الشكوى لتحديث حالتها") | |
| status_input = gr.Dropdown(choices=["Open", "Pending", "Closed"], label="الحالة الجديدة") | |
| update_status_button = gr.Button("تحديث الحالة") | |
| status_output = gr.Textbox(label="نتيجة التحديث") | |
| update_status_button.click(update_status, inputs=[complaint_id_input, status_input], outputs=status_output) | |
| export_button = gr.Button("تصدير الشكاوى إلى Excel") | |
| export_output = gr.Textbox(label="نتيجة التصدير") | |
| export_button.click(export_complaints, outputs=export_output) | |
| demo.launch(server_name="0.0.0.0", server_port=None) | |