Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,84 +1,57 @@
|
|
| 1 |
-
# app.py
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 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.
|
| 37 |
-
|
| 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 |
-
|
| 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 |
-
main()
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
|
| 4 |
+
# Load CSV file (to store complaint data)
|
| 5 |
+
file_path = "complaints.csv"
|
| 6 |
+
df = pd.read_csv(file_path)
|
| 7 |
+
|
| 8 |
+
# Layout - Title
|
| 9 |
+
st.title("ุชุทุจูู ุงูุดูุงูู ุงูุฅููุชุฑูููุฉ")
|
| 10 |
+
|
| 11 |
+
# Add login screen (just for structure, it can be improved later)
|
| 12 |
+
def login_screen():
|
| 13 |
+
st.subheader("ุชุณุฌูู ุงูุฏุฎูู")
|
| 14 |
+
user_type = st.selectbox("ุงุฎุชุฑ ููุน ุงูู
ุณุชุฎุฏู
:", ["ู
ูุฏู
ุดููู", "ู
ุณุชูุจู ุดููู"])
|
| 15 |
+
username = st.text_input("ุงุณู
ุงูู
ุณุชุฎุฏู
:")
|
| 16 |
+
password = st.text_input("ููู
ุฉ ุงูู
ุฑูุฑ:", type="password")
|
| 17 |
+
if st.button("ุฏุฎูู"):
|
| 18 |
+
if username and password:
|
| 19 |
+
return user_type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
else:
|
| 21 |
+
st.error("ุงูุฑุฌุงุก ุฅุฏุฎุงู ุงุณู
ุงูู
ุณุชุฎุฏู
ูููู
ุฉ ุงูู
ุฑูุฑ.")
|
| 22 |
+
return None
|
|
|
|
| 23 |
|
| 24 |
+
user_type = login_screen()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
if user_type:
|
| 27 |
+
if user_type == "ู
ูุฏู
ุดููู":
|
| 28 |
+
st.subheader("ุงูุดูุงูู ุงูู
ูุฏู
ุฉ")
|
| 29 |
+
user_complaints = df[df['ู
ูุฏู
ุงูุดููู'] == username] # Filter complaints by user
|
| 30 |
+
if not user_complaints.empty:
|
| 31 |
+
st.write(user_complaints)
|
| 32 |
+
else:
|
| 33 |
+
st.write("ูุง ุชูุฌุฏ ุดูุงูู ู
ูุฏู
ุฉ.")
|
| 34 |
+
|
| 35 |
+
elif user_type == "ู
ุณุชูุจู ุดููู":
|
| 36 |
+
st.subheader("ุฅุฏุงุฑุฉ ุงูุดูุงูู")
|
| 37 |
+
# Display all complaints for admin to handle
|
| 38 |
+
if not df.empty:
|
| 39 |
+
for index, row in df.iterrows():
|
| 40 |
+
st.write(f"### ุดููู ู
ู {row['ู
ูุฏู
ุงูุดููู']}")
|
| 41 |
+
st.write(f"**ุงููุตู:** {row['ูุตู ุงูุดููู']}")
|
| 42 |
+
st.write(f"**ุงูุญุงูุฉ ุงูุญุงููุฉ:** {row['ุญุงูุฉ ุงูุดููู']}")
|
| 43 |
+
|
| 44 |
+
# Option to change complaint status
|
| 45 |
+
new_status = st.selectbox(f"ุชุบููุฑ ุญุงูุฉ ุงูุดููู {row['ู
ูุฏู
ุงูุดููู']}", ["ููุฏ ุงูู
ุนุงูุฌุฉ", "ู
ุบููุฉ", "ุชู
ุงูุฑุฏ ุนูููุง"], key=index)
|
| 46 |
+
if st.button(f"ุชุญุฏูุซ ุญุงูุฉ ุงูุดููู {row['ู
ูุฏู
ุงูุดููู']}", key=f"update_{index}"):
|
| 47 |
+
df.at[index, 'ุญุงูุฉ ุงูุดููู'] = new_status
|
| 48 |
+
st.success(f"ุชู
ุชุญุฏูุซ ุญุงูุฉ ุงูุดููู ูู {row['ู
ูุฏู
ุงูุดููู']}")
|
| 49 |
+
|
| 50 |
+
# Option to add a response
|
| 51 |
+
response = st.text_area(f"ุฃุถู ุฑุฏูุง ุนูู ุงูุดููู ู
ู {row['ู
ูุฏู
ุงูุดููู']}", key=f"response_{index}")
|
| 52 |
+
if st.button(f"ุฅุฑุณุงู ุงูุฑุฏ ูู {row['ู
ูุฏู
ุงูุดููู']}", key=f"send_{index}"):
|
| 53 |
+
df.at[index, 'ุฑุฏ ุงูุดููู'] = response
|
| 54 |
+
st.success(f"ุชู
ุฅุฑุณุงู ุงูุฑุฏ ูู {row['ู
ูุฏู
ุงูุดููู']}")
|
| 55 |
+
|
| 56 |
+
# Save the changes back to CSV
|
| 57 |
+
df.to_csv(file_path, index=False)
|
|
|