Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app (9).py +84 -0
- complaints.csv +1 -0
- requirements (5).txt +2 -0
app (9).py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# بيانات المستخدمين (مؤقتًا ثابتة)
|
| 7 |
+
users = {
|
| 8 |
+
"user1": {"password": "1234", "role": "user"},
|
| 9 |
+
"admin1": {"password": "admin", "role": "admin"}
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
CSV_FILE = "complaints.csv"
|
| 13 |
+
|
| 14 |
+
# إنشاء الملف لو مش موجود
|
| 15 |
+
if not os.path.exists(CSV_FILE):
|
| 16 |
+
df = pd.DataFrame(columns=["id", "username", "complaint", "status", "response"])
|
| 17 |
+
df.to_csv(CSV_FILE, index=False)
|
| 18 |
+
|
| 19 |
+
# تحميل البيانات
|
| 20 |
+
def load_data():
|
| 21 |
+
return pd.read_csv(CSV_FILE)
|
| 22 |
+
|
| 23 |
+
# حفظ البيانات
|
| 24 |
+
def save_data(df):
|
| 25 |
+
df.to_csv(CSV_FILE, index=False)
|
| 26 |
+
|
| 27 |
+
# تسجيل الدخول
|
| 28 |
+
def login():
|
| 29 |
+
st.sidebar.title("🔐 Login")
|
| 30 |
+
username = st.sidebar.text_input("Username")
|
| 31 |
+
password = st.sidebar.text_input("Password", type="password")
|
| 32 |
+
if st.sidebar.button("Login"):
|
| 33 |
+
if username in users and users[username]["password"] == password:
|
| 34 |
+
return username, users[username]["role"]
|
| 35 |
+
else:
|
| 36 |
+
st.sidebar.error("❌ Invalid credentials")
|
| 37 |
+
return None, None
|
| 38 |
+
return None, None
|
| 39 |
+
|
| 40 |
+
# واجهة المستخدم العادي
|
| 41 |
+
def user_interface(username):
|
| 42 |
+
st.title("📨 Submit a Complaint")
|
| 43 |
+
complaint = st.text_area("Your Complaint")
|
| 44 |
+
if st.button("Submit"):
|
| 45 |
+
df = load_data()
|
| 46 |
+
new_id = len(df) + 1
|
| 47 |
+
new_row = pd.DataFrame([[new_id, username, complaint, "Open", ""]], columns=df.columns)
|
| 48 |
+
df = pd.concat([df, new_row], ignore_index=True)
|
| 49 |
+
save_data(df)
|
| 50 |
+
st.success("✅ Complaint submitted successfully!")
|
| 51 |
+
|
| 52 |
+
st.subheader("📋 Your Complaints")
|
| 53 |
+
df = load_data()
|
| 54 |
+
user_df = df[df["username"] == username]
|
| 55 |
+
st.table(user_df)
|
| 56 |
+
|
| 57 |
+
# واجهة المسؤول
|
| 58 |
+
def admin_interface():
|
| 59 |
+
st.title("🛠️ Admin Dashboard")
|
| 60 |
+
df = load_data()
|
| 61 |
+
|
| 62 |
+
for i, row in df.iterrows():
|
| 63 |
+
st.markdown(f"**Complaint #{row['id']} by {row['username']}**")
|
| 64 |
+
st.markdown(f"- Complaint: {row['complaint']}")
|
| 65 |
+
st.markdown(f"- Status: `{row['status']}`")
|
| 66 |
+
response = st.text_input(f"Response for Complaint #{row['id']}", value=row['response'], key=f"res_{row['id']}")
|
| 67 |
+
status = st.selectbox("Update Status", ["Open", "In Progress", "Closed"], index=["Open", "In Progress", "Closed"].index(row['status']), key=f"stat_{row['id']}")
|
| 68 |
+
if st.button(f"Update #{row['id']}"):
|
| 69 |
+
df.at[i, "response"] = response
|
| 70 |
+
df.at[i, "status"] = status
|
| 71 |
+
save_data(df)
|
| 72 |
+
st.success(f"✅ Complaint #{row['id']} updated.")
|
| 73 |
+
|
| 74 |
+
# التطبيق الرئيسي
|
| 75 |
+
def main():
|
| 76 |
+
username, role = login()
|
| 77 |
+
if username:
|
| 78 |
+
if role == "user":
|
| 79 |
+
user_interface(username)
|
| 80 |
+
elif role == "admin":
|
| 81 |
+
admin_interface()
|
| 82 |
+
|
| 83 |
+
if __name__ == "__main__":
|
| 84 |
+
main()
|
complaints.csv
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
id,username,complaint,status,response
|
requirements (5).txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pandas
|