Hadeeratef91 commited on
Commit
01fb230
ยท
verified ยท
1 Parent(s): 4a3f5ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -78
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
- 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()
 
 
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)