Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines910111213141516171837 unmodified lines565758596061625 unmodified lines68697071727374757677787980818283848586878 unmodified lines969798991001011021031041051061071081091101112 unmodified lines1141151161171181191201211221231241251261271282 unmodified lines1311321331341351361378 unmodified lines# تحميل أو إنشاء ملف CSVfile_path = "complaints.csv"if os.path.exists(file_path):df = pd.read_csv(file_path)else:df = pd.DataFrame(columns=["complaint_id", "username", "complaint_text", "status", "response", "timestamp"])df.to_csv(file_path, index=False)# -----------------------------------------# تهيئة session state37 unmodified linesst.warning("❌ اسم المستخدم غير موجود.")# -----------------------------------------# واجهة مقدم الشكوىelif st.session_state.user_type == "sender":st.title("📨 تقديم شكوى")complaint_text = st.text_area("وصف الشكوى")5 unmodified linescomplaint_id = f"{prefix}_{next_id:06}"timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")new_complaint = {"complaint_id": complaint_id,"username": st.session_state.username,"complaint_text": complaint_text,"status": "Pending","response": "","timestamp": timestamp}df = pd.concat([df, pd.DataFrame([new_complaint])], ignore_index=True)df.to_csv(file_path, index=False)st.success("✅ تم تقديم الشكوى بنجاح")st.rerun()# إشعار بتحديث حالة الشكوىuser_complaints = df[df["username"] == st.session_state.username]if not user_complaints.empty:last_complaint = user_complaints.iloc[-1]8 unmodified linesif st.button("🚪 تسجيل الخروج"):st.session_state.is_logged_in = Falsest.session_state.user_type = Nonest.session_state.username = ""st.rerun()# -----------------------------------------# واجهة مستقبل الشكوىelif st.session_state.user_type == "receiver":st.title("📬 إدارة الشكاوى")if df.empty:st.info("🚫 لا توجد شكاوى حالياً للتعامل معها.")else:current_count = len(df)new_complaints = current_count - st.session_state.last_seen_count2 unmodified linesst.session_state.last_seen_count = current_countst.subheader("📋 جميع الشكاوى")selected_index = st.selectbox("اختر شكوى للتعامل معها",df.index,format_func=lambda i: f"{df.loc[i, 'complaint_id']} - {df.loc[i, 'username']}")selected_row = df.loc[selected_index]st.write(f"### ✉️ شكوى: {selected_row['complaint_id']}")st.write(f"**اسم المستخدم:** {selected_row['username']}")st.write(f"**الوصف:** {selected_row['complaint_text']}")new_status = st.selectbox("🔄 تحديث الحالة", ["Pending", "In Progress", "Resolved"], index=["Pending", "In Progress", "Resolved"].index(selected_row["status"]))2 unmodified linesif st.button("💾 حفظ التعديلات"):df.at[selected_index, "status"] = new_statusdf.at[selected_index, "response"] = new_responsedf.to_csv(file_path, index=False)st.success("✅ تم حفظ التع��يلات")st.rerun()8 unmodified lines910111213141516171837 unmodified lines565758596061625 unmodified lines68697071727374757677787980818283848586878889909192938 unmodified lines1021031041051061071081091101111121131141151162 unmodified lines1191201211221231241251261271281292 unmodified lines1321331341351361371388 unmodified lines# تحميل أو إنشاء ملف CSVfile_path = "complaints.csv"if os.path.exists(file_path):df = pd.read_csv(file_path, encoding='utf-8-sig')else:df = pd.DataFrame(columns=["complaint_id", "username", "complaint_text", "status", "response", "timestamp"])df.to_csv(file_path, index=False, encoding='utf-8-sig')# -----------------------------------------# تهيئة session state37 unmodified linesst.warning("❌ اسم المستخدم غير موجود.")# -----------------------------------------# مقدم الشكوىelif st.session_state.user_type == "sender":st.title("📨 تقديم شكوى")complaint_text = st.text_area("وصف الشكوى")5 unmodified linescomplaint_id = f"{prefix}_{next_id:06}"timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")# التحقق من التكرارif not ((df["username"] == st.session_state.username) & (df["complaint_text"] == complaint_text)).any():new_complaint = {"complaint_id": complaint_id,"username": st.session_state.username,"complaint_text": complaint_text,"status": "Pending","response": "","timestamp": timestamp}df = pd.concat([df, pd.DataFrame([new_complaint])], ignore_index=True)df.to_csv(file_path, index=False, encoding='utf-8-sig')st.success("✅ تم تقديم الشكوى بنجاح")st.experimental_set_query_params(clear=True)st.rerun()else:st.warning("⚠️ تم إرسال هذه الشكوى بالفعل من قبل.")# إشعار بتحديث حالة الشكوى أو الردuser_complaints = df[df["username"] == st.session_state.username]if not user_complaints.empty:last_complaint = user_complaints.iloc[-1]8 unmodified linesif st.button("🚪 تسجيل الخروج"):st.session_state.is_logged_in = Falsest.session_state.user_type = Nonest.rerun()# -----------------------------------------# مستقبل الشكوىelif st.session_state.user_type == "receiver":st.title("📬 إدارة الشكاوى")if df.empty:st.info("لا توجد شكاوى حالياً للتعامل معها.")else:current_count = len(df)new_complaints = current_count - st.session_state.last_seen_count2 unmodified linesst.session_state.last_seen_count = current_countst.subheader("📋 جميع الشكاوى")selected_index = st.selectbox("اختر شكوى للتعامل معها", df.index, format_func=lambda i: f"{df.loc[i, 'complaint_id']} - {df.loc[i, 'username']}")selected_row = df.loc[selected_index]st.write(f"### ✉️ شكوى: {selected_row['complaint_id']}")st.write(f"**مقدم الشكوى:** {selected_row['username']}")st.write(f"**الوصف:** {selected_row['complaint_text']}")new_status = st.selectbox("🔄 تحديث الحالة", ["Pending", "In Progress", "Resolved"], index=["Pending", "In Progress", "Resolved"].index(selected_row["status"]))2 unmodified linesif st.button("💾 حفظ التعديلات"):df.at[selected_index, "status"] = new_statusdf.at[selected_index, "response"] = new_responsedf.to_csv(file_path, index=False, encoding='utf-8-sig')st.success("✅ تم حفظ التع��يلات")st.rerun()
app.py+27-26