jcho02's picture
Create app.py
c5db237
raw
history blame
1.54 kB
import gradio as gr
import pandas as pd
from google.colab import auth
import gspread
from google.auth import default
def feedback_response(feedback, comments):
response = ''
if feedback == 'Good Response':
response = 'Good Response!'
elif feedback == 'Bad Response':
response = 'Bad Response'
else:
response = 'Inappropriate response!'
if comments:
comments = comments
# Create a DataFrame from the response
auth.authenticate_user()
creds, _ = default()
gc = gspread.authorize(creds)
sheet_id = "18hnoTsEaGMWMael42MXubb-FzAe5jJB5RpaSolIXyb0"
worksheet_name = "Sheet1"
auth.authenticate_user()
creds, _ = default()
gc = gspread.authorize(creds)
sh = gc.open_by_key(sheet_id)
sh.worksheets()
worksheet = sh.worksheet(worksheet_name)
df = pd.DataFrame({'Response': [response],'Additional Comments': [comments]})
#worksheet.append_rows([df.columns.values.tolist()] + df.values.tolist())
worksheet.append_rows(df.values.tolist())
return "Your feedback has been recorded. Thank you!"
# Set up the Gradio Interface
feedback_interface = gr.Interface(
fn=feedback_response,
inputs=[
gr.Radio(
choices=[
"Good Response",
"Bad Response",
"Inappropriate Response"
],
label="Feedback"
),
gr.Textbox(label="Additional Comments")
],
outputs= "text"
)
# Launch the interface
feedback_interface.launch(share=True)