Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,8 +7,8 @@ import time
|
|
| 7 |
import json
|
| 8 |
|
| 9 |
# Authenticate and authorize with Google Sheets
|
| 10 |
-
#
|
| 11 |
-
#
|
| 12 |
gc = gspread.service_account(filename='botresponse-6f1a8c749aa0.json')
|
| 13 |
|
| 14 |
# Specify your Google Sheets credentials, sheet_id, and worksheet_name
|
|
@@ -40,46 +40,35 @@ def get_initial_response(input_message):
|
|
| 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,
|
| 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 == '
|
| 50 |
-
response = '
|
| 51 |
-
elif feedback == '
|
| 52 |
-
response = '
|
| 53 |
-
elif feedback == '
|
| 54 |
-
response = '
|
| 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
|
| 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], '
|
| 79 |
|
| 80 |
# Append the data to the worksheet
|
| 81 |
worksheet.append_rows(df.values.tolist())
|
| 82 |
initial_response = thankyou
|
|
|
|
| 83 |
|
| 84 |
return initial_response, elapsed_time # Return the initial_response and elapsed_time
|
| 85 |
|
|
@@ -88,32 +77,34 @@ feedback_interface = gr.Interface(
|
|
| 88 |
fn=feedback_response,
|
| 89 |
inputs=[
|
| 90 |
gr.Textbox(label="Input Message"),
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
gr.Textbox(label="Additional Comments")
|
| 94 |
],
|
| 95 |
outputs=[
|
| 96 |
gr.Textbox(label="Output", type="text"),
|
| 97 |
-
gr.Textbox(label="Elapsed Time (s)", type="text")
|
| 98 |
],
|
| 99 |
title="Beta: Itell Guide Response Bot",
|
| 100 |
description="""
|
| 101 |
# Introduction
|
| 102 |
This is an interface to test iTELL's guide on the side. Please be aware that responses can take up to 20 seconds
|
| 103 |
-
|
| 104 |
# Step by Step Introduction
|
| 105 |
1. Place a question in the input message textbox
|
| 106 |
2. Wait roughly 10 ~ 20 seconds for the response and elapsed time to come out on the right
|
| 107 |
-
3. After looking at the results, click on the feedback options that best
|
| 108 |
4. After choosing the best option, write down additional comments for more feedback
|
| 109 |
5. Press submit again and wait for the output to come out again for your feedback to be submitted
|
| 110 |
-
6. Once the "Thank you for your feedback. Your response and feedback
|
| 111 |
-
|
| 112 |
-
** DISCLAIMER: You have to type an input message, click on the feedback buttons, and type in additional comments for your responses to be recorded
|
| 113 |
-
|
| 114 |
** For further questions contact LEAR Labs!
|
| 115 |
"""
|
| 116 |
)
|
| 117 |
|
| 118 |
# Launch the interface
|
| 119 |
-
feedback_interface.launch()
|
|
|
|
| 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
|
|
|
|
| 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, 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 == 'Informative':
|
| 50 |
+
response = 'Informative'
|
| 51 |
+
elif feedback == 'Inaccurate':
|
| 52 |
+
response = 'Inaccurate'
|
| 53 |
+
elif feedback == 'Nonsense':
|
| 54 |
+
response = 'Nonsense'
|
| 55 |
else:
|
| 56 |
response = 'NA'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 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 |
|
|
|
|
| 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
|
| 96 |
This is an interface to test iTELL's guide on the side. Please be aware that responses can take up to 20 seconds
|
|
|
|
| 97 |
# Step by Step Introduction
|
| 98 |
1. Place a question in the input message textbox
|
| 99 |
2. Wait roughly 10 ~ 20 seconds for the response and elapsed time to come out on the right
|
| 100 |
+
3. After looking at the results, click on the feedback options that best describes the output: Informative, Inaccurate, Nonsense
|
| 101 |
4. After choosing the best option, write down additional comments for more feedback
|
| 102 |
5. Press submit again and wait for the output to come out again for your feedback to be submitted
|
| 103 |
+
6. Once the "Thank you for your feedback. Your response and feedback has been recorded!" message is shown, you are done
|
| 104 |
+
** DISCLAIMER: You have to type a input message, click on the feedback buttons, and type in additional comments for your responses to be recorded
|
|
|
|
|
|
|
| 105 |
** For further questions contact LEAR Labs!
|
| 106 |
"""
|
| 107 |
)
|
| 108 |
|
| 109 |
# Launch the interface
|
| 110 |
+
feedback_interface.launch()
|