jcho02 commited on
Commit
0010262
·
1 Parent(s): 6e49a6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -53
app.py CHANGED
@@ -3,14 +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
- # 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"
@@ -58,63 +58,38 @@ def feedback_response(input_message, feedback, comments):
58
  # Update Google Sheets
59
  sh = gc.open_by_key(sheet_id)
60
  worksheet = sh.worksheet(worksheet_name)
61
-
62
- thankyou = "Thank you for your feedback. Your response and feedback have been recorded!"
63
  # Append the data to the worksheet only if comments have a value
64
  if comments:
65
  # Create a DataFrame from the response and additional comments
66
- df = pd.DataFrame({'Input Message': [input_message], 'Output': [initial_response],
67
- 'Time took in Seconds': [elapsed_time], 'Feedback': [response],
68
- 'Additional Comments': [comments]})
69
 
70
  # Append the data to the worksheet
71
  worksheet.append_rows(df.values.tolist())
72
  initial_response = thankyou
73
 
 
74
  return initial_response, elapsed_time # Return the initial_response and elapsed_time
75
 
76
  # Set up the Gradio Interface
77
- input_message = gr.Textbox(label="Input Message")
78
- feedback_choice = gr.Radio(
79
- choices=[
80
- "Informative",
81
- "Inaccurate",
82
- "Nonsense"
 
 
 
 
 
 
 
 
 
 
83
  ],
84
- label="Feedback")
85
- additional_comments = gr.Textbox(label="Additional Comments")
86
-
87
- output_response = gr.Textbox(label="Output", type="text")
88
- output_elapsed_time = gr.Textbox(label="Elapsed Time (s)", type="text")
89
-
90
- # Create separate buttons for response and feedback submission
91
- response_button = gr.Button(value="Submit Response")
92
- feedback_button = gr.Button(value="Submit Feedback")
93
-
94
- # Create functions for response and feedback submission
95
- def submit_response():
96
- input_text = input_message.value
97
- response, elapsed_time = feedback_response(input_text, "", "")
98
- output_response.value = response
99
- output_elapsed_time.value = str(elapsed_time)
100
-
101
- def submit_feedback():
102
- input_text = input_message.value
103
- feedback = feedback_choice.value
104
- comments = additional_comments.value
105
- response, elapsed_time = feedback_response(input_text, feedback, comments)
106
- output_response.value = response
107
- output_elapsed_time.value = str(elapsed_time)
108
-
109
- # Set the functions for button clicks
110
- response_button.click(submit_response)
111
- feedback_button.click(submit_feedback)
112
-
113
- # Create the Gradio interface with buttons
114
- gr.Interface(
115
- fn=None,
116
- inputs=[input_message, feedback_choice, additional_comments, response_button, feedback_button],
117
- outputs=[output_response, output_elapsed_time],
118
  title="Beta: Itell Guide Response Bot",
119
  description="""
120
  # Introduction
@@ -123,13 +98,16 @@ gr.Interface(
123
  # Step by Step Introduction
124
  1. Place a question in the input message textbox
125
  2. Wait roughly 10 ~ 20 seconds for the response and elapsed time to come out on the right
126
- 3. After looking at the results, select the feedback option that best describes the output: Informative, Inaccurate, Nonsense
127
  4. After choosing the best option, write down additional comments for more feedback
128
  5. Press submit again and wait for the output to come out again for your feedback to be submitted
129
- 6. Once the "Thank you for your feedback. Your response and feedback have been recorded!" message is shown, you are done
130
 
131
- ** DISCLAIMER: You have to type an input message, select a feedback option, and type in additional comments for your responses to be recorded
132
 
133
  ** For further questions contact LEAR Labs!
134
  """
135
- ).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"
 
58
  # Update Google Sheets
59
  sh = gc.open_by_key(sheet_id)
60
  worksheet = sh.worksheet(worksheet_name)
61
+
62
+ thankyou = "Thank you for your feedback. Your response and feedback has been recorded!"
63
  # Append the data to the worksheet only if comments have a value
64
  if comments:
65
  # Create a DataFrame from the response and additional comments
66
+ df = pd.DataFrame({'Input Message': [input_message], 'Output': [initial_response], 'Time took in Seconds': [elapsed_time],'Feedback': [response], 'Additional Comments': [comments]})
 
 
67
 
68
  # Append the data to the worksheet
69
  worksheet.append_rows(df.values.tolist())
70
  initial_response = thankyou
71
 
72
+
73
  return initial_response, elapsed_time # Return the initial_response and elapsed_time
74
 
75
  # Set up the Gradio Interface
76
+ feedback_interface = gr.Interface(
77
+ fn=feedback_response,
78
+ inputs=[
79
+ gr.Textbox(label="Input Message"),
80
+ gr.Radio(
81
+ choices=[
82
+ "Informative",
83
+ "Inaccurate",
84
+ "Nonsense"
85
+ ],
86
+ label="Feedback"),
87
+ gr.Textbox(label="Additional Comments")
88
+ ],
89
+ outputs=[
90
+ gr.Textbox(label="Output", type="text"),
91
+ gr.Textbox(label="Elapsed Time (s)", type="text") # Change the type to "text" for two decimal places
92
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  title="Beta: Itell Guide Response Bot",
94
  description="""
95
  # Introduction
 
98
  # Step by Step Introduction
99
  1. Place a question in the input message textbox
100
  2. Wait roughly 10 ~ 20 seconds for the response and elapsed time to come out on the right
101
+ 3. After looking at the results, click on the feedback options that best describes the output: Informative, Inaccurate, Nonsense
102
  4. After choosing the best option, write down additional comments for more feedback
103
  5. Press submit again and wait for the output to come out again for your feedback to be submitted
104
+ 6. Once the "Thank you for your feedback. Your response and feedback has been recorded!" message is shown, you are done
105
 
106
+ ** DISCLAIMER: You have to type a input message, click on the feedback buttons, and type in additional comments for your responses to be recorded
107
 
108
  ** For further questions contact LEAR Labs!
109
  """
110
+ )
111
+
112
+ # Launch the interface
113
+ feedback_interface.launch()