blind1234 commited on
Commit
203ac1d
·
verified ·
1 Parent(s): c3b41a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -23
app.py CHANGED
@@ -35,72 +35,134 @@ def submit_feedback(admin_username, message):
35
  "message": [message]
36
  })
37
  user_feedback.to_csv("user_feedback.csv", mode='a', header=False, index=False)
38
- return "Feedback submitted successfully!"
39
 
40
  # Function to create new admin account
41
  def create_admin(new_username, new_password):
 
 
 
42
  credentials = load_admin_credentials()
43
  if new_username in credentials:
44
- return "Username already exists!"
45
 
46
  credentials[new_username] = hashlib.sha256(new_password.encode()).hexdigest()
47
  save_admin_credentials(credentials)
48
- return f"New admin account '{new_username}' created successfully!"
49
 
50
  # Function to view feedback messages
51
  def view_messages(username, password):
52
  credentials = load_admin_credentials()
53
  hashed_password = hashlib.sha256(password.encode()).hexdigest()
54
  if username not in credentials or credentials[username] != hashed_password:
55
- return "Invalid credentials!"
56
 
57
  try:
58
  df = pd.read_csv("user_feedback.csv", names=["timestamp", "admin", "message"])
59
  admin_messages = df[df['admin'] == username]
60
  if admin_messages.empty:
61
- return "No messages found for your account."
62
  return admin_messages.to_string()
63
  except FileNotFoundError:
64
- return "No messages found."
65
  except Exception as e:
66
- return f"Error reading messages: {str(e)}"
67
 
68
  # Create Gradio interface
69
  with gr.Blocks() as demo:
70
- gr.Markdown("# Feedback System")
 
71
 
72
- with gr.Tab("Submit Feedback"):
73
- admin_select = gr.Dropdown(choices=get_admin_usernames(), label="Select Admin")
74
- feedback_input = gr.Textbox(label="Your Feedback", lines=3)
75
- submit_button = gr.Button("Submit Feedback")
76
- feedback_output = gr.Textbox(label="Result")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  submit_button.click(
78
  fn=submit_feedback,
79
  inputs=[admin_select, feedback_input],
80
  outputs=feedback_output
81
  )
82
 
83
- with gr.Tab("Admin Login"):
84
- login_username = gr.Dropdown(choices=get_admin_usernames(), label="Admin Username")
85
- login_password = gr.Textbox(label="Password", type="password")
86
- view_messages_btn = gr.Button("View Messages")
87
- messages_output = gr.Textbox(label="Messages", lines=10)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  view_messages_btn.click(
89
  fn=view_messages,
90
  inputs=[login_username, login_password],
91
  outputs=messages_output
92
  )
93
 
94
- with gr.Tab("Create New Admin"):
95
- new_username = gr.Textbox(label="New Admin Username")
96
- new_password = gr.Textbox(label="New Admin Password", type="password")
97
- create_button = gr.Button("Create New Admin")
98
- create_output = gr.Textbox(label="Result")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  create_button.click(
100
  fn=create_admin,
101
  inputs=[new_username, new_password],
102
  outputs=create_output
103
  )
104
 
 
 
 
105
  # Launch the Gradio app
106
  demo.launch(show_error=True)
 
35
  "message": [message]
36
  })
37
  user_feedback.to_csv("user_feedback.csv", mode='a', header=False, index=False)
38
+ return "Your feedback has been successfully submitted to the selected administrator."
39
 
40
  # Function to create new admin account
41
  def create_admin(new_username, new_password):
42
+ if not new_username or not new_password:
43
+ return "Please fill in both username and password fields."
44
+
45
  credentials = load_admin_credentials()
46
  if new_username in credentials:
47
+ return "This username is already taken. Please choose a different username."
48
 
49
  credentials[new_username] = hashlib.sha256(new_password.encode()).hexdigest()
50
  save_admin_credentials(credentials)
51
+ return f"Success! New administrator account for '{new_username}' has been created. You can now log in using these credentials."
52
 
53
  # Function to view feedback messages
54
  def view_messages(username, password):
55
  credentials = load_admin_credentials()
56
  hashed_password = hashlib.sha256(password.encode()).hexdigest()
57
  if username not in credentials or credentials[username] != hashed_password:
58
+ return "Login failed. Please check your username and password and try again."
59
 
60
  try:
61
  df = pd.read_csv("user_feedback.csv", names=["timestamp", "admin", "message"])
62
  admin_messages = df[df['admin'] == username]
63
  if admin_messages.empty:
64
+ return "You have no messages at this time."
65
  return admin_messages.to_string()
66
  except FileNotFoundError:
67
+ return "No messages found in the system."
68
  except Exception as e:
69
+ return f"An error occurred while retrieving messages: {str(e)}"
70
 
71
  # Create Gradio interface
72
  with gr.Blocks() as demo:
73
+ gr.Markdown("# Feedback Management System")
74
+ gr.Markdown("Welcome to the Feedback Management System. Please select a tab below to continue.")
75
 
76
+ with gr.Tab("Submit Feedback", elem_id="submit_tab"):
77
+ gr.Markdown("### Submit Your Feedback")
78
+ gr.Markdown("Please select an administrator and enter your feedback message below.")
79
+ admin_select = gr.Dropdown(
80
+ choices=get_admin_usernames(),
81
+ label="Select Administrator",
82
+ info="Choose the administrator who should receive your feedback",
83
+ elem_id="admin_select"
84
+ )
85
+ feedback_input = gr.Textbox(
86
+ label="Your Feedback Message",
87
+ lines=3,
88
+ placeholder="Type your feedback here",
89
+ info="Enter your feedback message in detail",
90
+ elem_id="feedback_input"
91
+ )
92
+ submit_button = gr.Button("Submit Feedback", elem_id="submit_button")
93
+ feedback_output = gr.Textbox(
94
+ label="Submission Status",
95
+ interactive=False,
96
+ elem_id="feedback_status"
97
+ )
98
  submit_button.click(
99
  fn=submit_feedback,
100
  inputs=[admin_select, feedback_input],
101
  outputs=feedback_output
102
  )
103
 
104
+ with gr.Tab("Administrator Login", elem_id="login_tab"):
105
+ gr.Markdown("### Administrator Login")
106
+ gr.Markdown("Please log in with your administrator credentials to view messages.")
107
+ login_username = gr.Dropdown(
108
+ choices=get_admin_usernames(),
109
+ label="Administrator Username",
110
+ info="Select your username from the list",
111
+ elem_id="login_username"
112
+ )
113
+ login_password = gr.Textbox(
114
+ label="Password",
115
+ type="password",
116
+ placeholder="Enter your password",
117
+ info="Enter your administrator password",
118
+ elem_id="login_password"
119
+ )
120
+ view_messages_btn = gr.Button("View Messages", elem_id="view_messages_button")
121
+ messages_output = gr.Textbox(
122
+ label="Messages",
123
+ lines=10,
124
+ interactive=False,
125
+ elem_id="messages_display"
126
+ )
127
  view_messages_btn.click(
128
  fn=view_messages,
129
  inputs=[login_username, login_password],
130
  outputs=messages_output
131
  )
132
 
133
+ with gr.Tab("Create Administrator Account", elem_id="create_account_tab"):
134
+ gr.Markdown("### Create New Administrator Account")
135
+ gr.Markdown("Fill in the fields below to create a new administrator account.")
136
+ new_username = gr.Textbox(
137
+ label="New Administrator Username",
138
+ placeholder="Enter desired username",
139
+ info="Choose a unique username for the new administrator account",
140
+ elem_id="new_username"
141
+ )
142
+ new_password = gr.Textbox(
143
+ label="New Administrator Password",
144
+ type="password",
145
+ placeholder="Enter desired password",
146
+ info="Choose a secure password for the account",
147
+ elem_id="new_password"
148
+ )
149
+ create_button = gr.Button(
150
+ "Create Administrator Account",
151
+ elem_id="create_account_button"
152
+ )
153
+ create_output = gr.Textbox(
154
+ label="Account Creation Status",
155
+ interactive=False,
156
+ elem_id="creation_status"
157
+ )
158
  create_button.click(
159
  fn=create_admin,
160
  inputs=[new_username, new_password],
161
  outputs=create_output
162
  )
163
 
164
+ gr.Markdown("### Need Help?")
165
+ gr.Markdown("If you need assistance, please contact system support.")
166
+
167
  # Launch the Gradio app
168
  demo.launch(show_error=True)