Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,105 +6,56 @@ import requests
|
|
| 6 |
import time
|
| 7 |
import json
|
| 8 |
|
| 9 |
-
#
|
| 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"
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
"message": input_message
|
| 23 |
}
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 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'
|
| 57 |
-
elif feedback == 'Inappropriate':
|
| 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], 'Time took in Seconds': [elapsed_time],'Feedback': [response], 'Additional Comments': [comments]})
|
| 71 |
-
|
| 72 |
-
# Append the data to the worksheet
|
| 73 |
-
worksheet.append_rows(df.values.tolist())
|
| 74 |
-
initial_response = thankyou
|
| 75 |
-
|
| 76 |
-
return initial_response, elapsed_time # Return the initial_response and elapsed_time
|
| 77 |
|
| 78 |
# Set up the Gradio Interface
|
| 79 |
feedback_interface = gr.Interface(
|
| 80 |
fn=feedback_response,
|
| 81 |
inputs=[
|
| 82 |
gr.Textbox(label="Input Message"),
|
| 83 |
-
gr.Row([
|
| 84 |
-
gr.ButtonGroup(
|
| 85 |
-
choices=[
|
| 86 |
-
"Good",
|
| 87 |
-
"Bad",
|
| 88 |
-
"Inappropriate"
|
| 89 |
-
],
|
| 90 |
-
label="Feedback (Top Row)",
|
| 91 |
-
type="radio"
|
| 92 |
-
),
|
| 93 |
-
gr.ButtonGroup(
|
| 94 |
-
choices=[
|
| 95 |
-
"Informative",
|
| 96 |
-
"Inaccurate",
|
| 97 |
-
"Nonsense"
|
| 98 |
-
],
|
| 99 |
-
label="Feedback (Bottom Row)",
|
| 100 |
-
type="radio"
|
| 101 |
-
)
|
| 102 |
-
]),
|
| 103 |
gr.Textbox(label="Additional Comments")
|
| 104 |
],
|
| 105 |
outputs=[
|
| 106 |
-
gr.
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
],
|
| 109 |
title="Beta: Itell Guide Response Bot",
|
| 110 |
description="""
|
|
|
|
| 6 |
import time
|
| 7 |
import json
|
| 8 |
|
| 9 |
+
# ... (The rest of your code remains the same)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Define custom CSS styles for the buttons
|
| 12 |
+
custom_css = """
|
| 13 |
+
<style>
|
| 14 |
+
.button-container {
|
| 15 |
+
display: flex;
|
| 16 |
+
justify-content: space-between;
|
|
|
|
| 17 |
}
|
| 18 |
+
.feedback-button {
|
| 19 |
+
background-color: #008CBA;
|
| 20 |
+
color: white;
|
| 21 |
+
border: none;
|
| 22 |
+
padding: 10px 20px;
|
| 23 |
+
text-align: center;
|
| 24 |
+
text-decoration: none;
|
| 25 |
+
display: inline-block;
|
| 26 |
+
font-size: 16px;
|
| 27 |
+
margin: 4px 2px;
|
| 28 |
+
cursor: pointer;
|
| 29 |
+
border-radius: 5px;
|
| 30 |
+
}
|
| 31 |
+
.feedback-button:hover {
|
| 32 |
+
background-color: #005e87;
|
| 33 |
+
}
|
| 34 |
+
</style>
|
| 35 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# Set up the Gradio Interface
|
| 38 |
feedback_interface = gr.Interface(
|
| 39 |
fn=feedback_response,
|
| 40 |
inputs=[
|
| 41 |
gr.Textbox(label="Input Message"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
gr.Textbox(label="Additional Comments")
|
| 43 |
],
|
| 44 |
outputs=[
|
| 45 |
+
gr.HTML(label="Feedback (Top Row)", html=custom_css + """
|
| 46 |
+
<div class="button-container">
|
| 47 |
+
<button class="feedback-button" id="good-feedback" onclick="setFeedback('Good')">Good</button>
|
| 48 |
+
<button class="feedback-button" id="bad-feedback" onclick="setFeedback('Bad')">Bad</button>
|
| 49 |
+
<button class="feedback-button" id="inappropriate-feedback" onclick="setFeedback('Inappropriate')">Inappropriate</button>
|
| 50 |
+
</div>
|
| 51 |
+
"""),
|
| 52 |
+
gr.HTML(label="Feedback (Bottom Row)", html=custom_css + """
|
| 53 |
+
<div class="button-container">
|
| 54 |
+
<button class="feedback-button" id="informative-feedback" onclick="setFeedback('Informative')">Informative</button>
|
| 55 |
+
<button class="feedback-button" id="inaccurate-feedback" onclick="setFeedback('Inaccurate')">Inaccurate</button>
|
| 56 |
+
<button class="feedback-button" id="nonsense-feedback" onclick="setFeedback('Nonsense')">Nonsense</button>
|
| 57 |
+
</div>
|
| 58 |
+
""")
|
| 59 |
],
|
| 60 |
title="Beta: Itell Guide Response Bot",
|
| 61 |
description="""
|