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