jcho02 commited on
Commit
959499b
·
1 Parent(s): 8439fac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -61
app.py CHANGED
@@ -3,12 +3,14 @@ import pandas as pd
3
  import gspread
4
  from google.auth import default
5
  import requests
6
- import time
7
  import json
8
 
9
  # Authenticate and authorize with Google Sheets
 
 
10
  gc = gspread.service_account(filename='botresponse-6f1a8c749aa0.json')
11
-
12
  # Specify your Google Sheets credentials, sheet_id, and worksheet_name
13
  sheet_id = "18hnoTsEaGMWMael42MXubb-FzAe5jJB5RpaSolIXyb0"
14
  worksheet_name = "Sheet1"
@@ -38,19 +40,13 @@ def get_initial_response(input_message):
38
  return message, response_time_message # Return the initial_response and elapsed_time
39
 
40
  # Function to collect feedback and update the spreadsheet
41
- def feedback_response(input_message, feedback, comments):
42
  # Get the initial response and elapsed_time
43
  initial_response, elapsed_time = get_initial_response(input_message)
44
 
45
  # Collect feedback
46
  response = ''
47
- if feedback == 'Informative':
48
- response = 'Informative'
49
- elif feedback == 'Inaccurate':
50
- response = 'Inaccurate'
51
- elif feedback == 'Nonsense':
52
- response = 'Nonsense'
53
- elif feedback == 'Good':
54
  response = 'Good'
55
  elif feedback == 'Bad':
56
  response = 'Bad'
@@ -58,90 +54,75 @@ def feedback_response(input_message, feedback, comments):
58
  response = 'Inappropriate'
59
  else:
60
  response = 'NA'
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  # Update Google Sheets
63
  sh = gc.open_by_key(sheet_id)
64
  worksheet = sh.worksheet(worksheet_name)
65
-
66
- thankyou = "Thank you for your feedback. Your response and feedback have been recorded!"
67
  # Append the data to the worksheet only if comments have a value
68
  if comments:
69
  # Create a DataFrame from the response and additional comments
70
- df = pd.DataFrame({'Input Message': [input_message], 'Output': [initial_response],
71
- 'Time took in Seconds': [elapsed_time], 'Feedback': [response],
72
- 'Additional Comments': [comments]})
73
 
74
  # Append the data to the worksheet
75
  worksheet.append_rows(df.values.tolist())
76
  initial_response = thankyou
77
 
 
78
  return initial_response, elapsed_time # Return the initial_response and elapsed_time
79
 
80
- # Define custom CSS styles for the buttons
81
- custom_css = """
82
- <style>
83
- .feedback-button {
84
- background-color: #008CBA;
85
- color: white;
86
- border: none;
87
- padding: 10px 20px;
88
- text-align: center;
89
- text-decoration: none;
90
- display: inline-block;
91
- font-size: 16px;
92
- margin: 4px 2px;
93
- cursor: pointer;
94
- border-radius: 5px;
95
- }
96
- .feedback-button:hover {
97
- background-color: #005e87;
98
- }
99
- </style>
100
- """
101
-
102
- # Define the custom HTML for the buttons
103
- custom_html = custom_css + """
104
- <div>
105
- <label>Feedback (Top Row):</label>
106
- <button class="feedback-button" onclick="setFeedback('Good')">Good</button>
107
- <button class="feedback-button" onclick="setFeedback('Bad')">Bad</button>
108
- <button class="feedback-button" onclick="setFeedback('Inappropriate')">Inappropriate</button>
109
- </div>
110
- <div>
111
- <label>Feedback (Bottom Row):</label>
112
- <button class="feedback-button" onclick="setFeedback('Informative')">Informative</button>
113
- <button class="feedback-button" onclick="setFeedback('Inaccurate')">Inaccurate</button>
114
- <button class="feedback-button" onclick="setFeedback('Nonsense')">Nonsense</button>
115
- </div>
116
- """
117
-
118
- # Set up the Gradio Interface with HTML components for custom buttons
119
  feedback_interface = gr.Interface(
120
  fn=feedback_response,
121
  inputs=[
122
  gr.Textbox(label="Input Message"),
123
- gr.HTML(label="Feedback Buttons", html=custom_html),
 
 
 
 
 
 
 
 
 
124
  gr.Textbox(label="Additional Comments")
125
  ],
126
  outputs=[
127
  gr.Textbox(label="Output", type="text"),
128
- gr.Textbox(label="Elapsed Time (s)", type="text")
129
  ],
130
  title="Beta: Itell Guide Response Bot",
131
  description="""
132
  # Introduction
133
  This is an interface to test iTELL's guide on the side. Please be aware that responses can take up to 20 seconds
 
134
  # Step by Step Introduction
135
  1. Place a question in the input message textbox
136
  2. Wait roughly 10 ~ 20 seconds for the response and elapsed time to come out on the right
137
- 3. After looking at the results, click on the feedback options that best describe the output: Good, Bad, Inappropriate, Informative, Inaccurate, Nonsense
138
  4. After choosing the best option, write down additional comments for more feedback
139
  5. Press submit again and wait for the output to come out again for your feedback to be submitted
140
- 6. Once the "Thank you for your feedback. Your response and feedback have been recorded!" message is shown, you are done
141
- ** DISCLAIMER: You have to type an input message, click on the feedback buttons, and type in additional comments for your responses to be recorded
142
- ** For further questions, contact LEAR Labs!
 
 
143
  """
144
  )
145
 
146
  # Launch the interface
147
- feedback_interface.launch()
 
3
  import gspread
4
  from google.auth import default
5
  import requests
6
+ import time
7
  import json
8
 
9
  # Authenticate and authorize with Google Sheets
10
+ #creds, _ = default()
11
+ #gc = gspread.authorize(creds)
12
  gc = gspread.service_account(filename='botresponse-6f1a8c749aa0.json')
13
+
14
  # Specify your Google Sheets credentials, sheet_id, and worksheet_name
15
  sheet_id = "18hnoTsEaGMWMael42MXubb-FzAe5jJB5RpaSolIXyb0"
16
  worksheet_name = "Sheet1"
 
40
  return message, response_time_message # Return the initial_response and elapsed_time
41
 
42
  # Function to collect feedback and update the spreadsheet
43
+ def feedback_response(input_message, feedback, add_feedback, comments):
44
  # Get the initial response and elapsed_time
45
  initial_response, elapsed_time = get_initial_response(input_message)
46
 
47
  # Collect feedback
48
  response = ''
49
+ if feedback == 'Good':
 
 
 
 
 
 
50
  response = 'Good'
51
  elif feedback == 'Bad':
52
  response = 'Bad'
 
54
  response = 'Inappropriate'
55
  else:
56
  response = 'NA'
57
+
58
+ # More feedback
59
+ # Collect feedback
60
+ add_response = ''
61
+ if add_feedback == 'Informative':
62
+ add_response = 'Informative'
63
+ elif add_feedback == 'Inaccurate':
64
+ add_response = 'Inaccurate'
65
+ elif add_feedback == 'Nonsense':
66
+ add_response = 'Nonsense'
67
+ else:
68
+ add_response = 'NA'
69
 
70
  # Update Google Sheets
71
  sh = gc.open_by_key(sheet_id)
72
  worksheet = sh.worksheet(worksheet_name)
73
+
74
+ thankyou = "Thank you for your feedback. Your response and feedback has been recorded!"
75
  # Append the data to the worksheet only if comments have a value
76
  if comments:
77
  # Create a DataFrame from the response and additional comments
78
+ df = pd.DataFrame({'Input Message': [input_message], 'Output': [initial_response], 'Time took in Seconds': [elapsed_time],'Feedback': [response], 'add_feedback': [add_response], 'Additional Comments': [comments]})
 
 
79
 
80
  # Append the data to the worksheet
81
  worksheet.append_rows(df.values.tolist())
82
  initial_response = thankyou
83
 
84
+
85
  return initial_response, elapsed_time # Return the initial_response and elapsed_time
86
 
87
+ # Set up the Gradio Interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  feedback_interface = gr.Interface(
89
  fn=feedback_response,
90
  inputs=[
91
  gr.Textbox(label="Input Message"),
92
+ gr.Radio(
93
+ choices=[
94
+ "Good",
95
+ "Bad",
96
+ "Inappropriate",
97
+ "Informative",
98
+ "Inaccurate",
99
+ "Nonsense"
100
+ ],
101
+ label="Feedback"),
102
  gr.Textbox(label="Additional Comments")
103
  ],
104
  outputs=[
105
  gr.Textbox(label="Output", type="text"),
106
+ gr.Textbox(label="Elapsed Time (s)", type="text") # Change the type to "text" for two decimal places
107
  ],
108
  title="Beta: Itell Guide Response Bot",
109
  description="""
110
  # Introduction
111
  This is an interface to test iTELL's guide on the side. Please be aware that responses can take up to 20 seconds
112
+
113
  # Step by Step Introduction
114
  1. Place a question in the input message textbox
115
  2. Wait roughly 10 ~ 20 seconds for the response and elapsed time to come out on the right
116
+ 3. After looking at the results, click on the feedback options that best describes the output: Informative, Inaccurate, Nonsense
117
  4. After choosing the best option, write down additional comments for more feedback
118
  5. Press submit again and wait for the output to come out again for your feedback to be submitted
119
+ 6. Once the "Thank you for your feedback. Your response and feedback has been recorded!" message is shown, you are done
120
+
121
+ ** DISCLAIMER: You have to type a input message, click on the feedback buttons, and type in additional comments for your responses to be recorded
122
+
123
+ ** For further questions contact LEAR Labs!
124
  """
125
  )
126
 
127
  # Launch the interface
128
+ feedback_interface.launch()