Spaces:
Sleeping
Sleeping
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384# app.pyimport streamlit as stimport pandas as pdimport 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, Nonereturn 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) + 1new_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"] = responsedf.at[i, "status"] = statussave_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()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import streamlit as stimport pandas as pd# Load CSV file (to store complaint data)file_path = "complaints.csv"df = pd.read_csv(file_path)# Layout - Titlest.title("ุชุทุจูู ุงูุดูุงูู ุงูุฅููุชุฑูููุฉ")# Add login screen (just for structure, it can be improved later)def login_screen():st.subheader("ุชุณุฌูู ุงูุฏุฎูู")user_type = st.selectbox("ุงุฎุชุฑ ููุน ุงูู ุณุชุฎุฏู :", ["ู ูุฏู ุดููู", "ู ุณุชูุจู ุดููู"])username = st.text_input("ุงุณู ุงูู ุณุชุฎุฏู :")password = st.text_input("ููู ุฉ ุงูู ุฑูุฑ:", type="password")if st.button("ุฏุฎูู"):if username and password:return user_typeelse:st.error("ุงูุฑุฌุงุก ุฅุฏุฎุงู ุงุณู ุงูู ุณุชุฎุฏู ูููู ุฉ ุงูู ุฑูุฑ.")return Noneuser_type = login_screen()if user_type:if user_type == "ู ูุฏู ุดููู":st.subheader("ุงูุดูุงูู ุงูู ูุฏู ุฉ")user_complaints = df[df['ู ูุฏู ุงูุดููู'] == username] # Filter complaints by userif not user_complaints.empty:st.write(user_complaints)else:st.write("ูุง ุชูุฌุฏ ุดูุงูู ู ูุฏู ุฉ.")elif user_type == "ู ุณุชูุจู ุดููู":st.subheader("ุฅุฏุงุฑุฉ ุงูุดูุงูู")# Display all complaints for admin to handleif not df.empty:for index, row in df.iterrows():st.write(f"### ุดููู ู ู {row['ู ูุฏู ุงูุดููู']}")st.write(f"**ุงููุตู:** {row['ูุตู ุงูุดููู']}")st.write(f"**ุงูุญุงูุฉ ุงูุญุงููุฉ:** {row['ุญุงูุฉ ุงูุดููู']}")# Option to change complaint statusnew_status = st.selectbox(f"ุชุบููุฑ ุญุงูุฉ ุงูุดููู {row['ู ูุฏู ุงูุดููู']}", ["ููุฏ ุงูู ุนุงูุฌุฉ", "ู ุบููุฉ", "ุชู ุงูุฑุฏ ุนูููุง"], key=index)if st.button(f"ุชุญุฏูุซ ุญุงูุฉ ุงูุดููู {row['ู ูุฏู ุงูุดููู']}", key=f"update_{index}"):df.at[index, 'ุญุงูุฉ ุงูุดููู'] = new_statusst.success(f"ุชู ุชุญุฏูุซ ุญุงูุฉ ุงูุดููู ูู {row['ู ูุฏู ุงูุดููู']}")# Option to add a responseresponse = st.text_area(f"ุฃุถู ุฑุฏูุง ุนูู ุงูุดููู ู ู {row['ู ูุฏู ุงูุดููู']}", key=f"response_{index}")if st.button(f"ุฅุฑุณุงู ุงูุฑุฏ ูู {row['ู ูุฏู ุงูุดููู']}", key=f"send_{index}"):df.at[index, 'ุฑุฏ ุงูุดููู'] = responsest.success(f"ุชู ุฅุฑุณุงู ุงูุฑุฏ ูู {row['ู ูุฏู ุงูุดููู']}")# Save the changes back to CSVdf.to_csv(file_path, index=False)
app.py+51-78