Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from google.colab import auth
|
| 4 |
+
import gspread
|
| 5 |
+
from google.auth import default
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def feedback_response(feedback, comments):
|
| 9 |
+
response = ''
|
| 10 |
+
if feedback == 'Good Response':
|
| 11 |
+
response = 'Good Response!'
|
| 12 |
+
elif feedback == 'Bad Response':
|
| 13 |
+
response = 'Bad Response'
|
| 14 |
+
else:
|
| 15 |
+
response = 'Inappropriate response!'
|
| 16 |
+
if comments:
|
| 17 |
+
comments = comments
|
| 18 |
+
|
| 19 |
+
# Create a DataFrame from the response
|
| 20 |
+
auth.authenticate_user()
|
| 21 |
+
creds, _ = default()
|
| 22 |
+
gc = gspread.authorize(creds)
|
| 23 |
+
sheet_id = "18hnoTsEaGMWMael42MXubb-FzAe5jJB5RpaSolIXyb0"
|
| 24 |
+
worksheet_name = "Sheet1"
|
| 25 |
+
auth.authenticate_user()
|
| 26 |
+
creds, _ = default()
|
| 27 |
+
gc = gspread.authorize(creds)
|
| 28 |
+
sh = gc.open_by_key(sheet_id)
|
| 29 |
+
sh.worksheets()
|
| 30 |
+
worksheet = sh.worksheet(worksheet_name)
|
| 31 |
+
df = pd.DataFrame({'Response': [response],'Additional Comments': [comments]})
|
| 32 |
+
#worksheet.append_rows([df.columns.values.tolist()] + df.values.tolist())
|
| 33 |
+
worksheet.append_rows(df.values.tolist())
|
| 34 |
+
return "Your feedback has been recorded. Thank you!"
|
| 35 |
+
|
| 36 |
+
# Set up the Gradio Interface
|
| 37 |
+
feedback_interface = gr.Interface(
|
| 38 |
+
fn=feedback_response,
|
| 39 |
+
inputs=[
|
| 40 |
+
gr.Radio(
|
| 41 |
+
choices=[
|
| 42 |
+
"Good Response",
|
| 43 |
+
"Bad Response",
|
| 44 |
+
"Inappropriate Response"
|
| 45 |
+
],
|
| 46 |
+
label="Feedback"
|
| 47 |
+
),
|
| 48 |
+
gr.Textbox(label="Additional Comments")
|
| 49 |
+
],
|
| 50 |
+
outputs= "text"
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
# Launch the interface
|
| 54 |
+
feedback_interface.launch(share=True)
|