Spaces:
Runtime error
Runtime error
import gradio as gr | |
import pandas as pd | |
import gspread | |
from google.auth import default | |
# Authenticate and authorize with Google Sheets | |
#creds, _ = default() | |
#gc = gspread.authorize(creds) | |
gc = gspread.service_account(filename='botresponse-6f1a8c749aa0.json') | |
# Specify your Google Sheets credentials, sheet_id, and worksheet_name | |
sheet_id = "18hnoTsEaGMWMael42MXubb-FzAe5jJB5RpaSolIXyb0" | |
worksheet_name = "Sheet1" | |
def feedback_response(feedback, comments, new_input_query): | |
response = '' | |
if feedback == 'Informative': | |
response = 'Informative!' | |
elif feedback == 'Inaccurate': | |
response = 'Inaccurate' | |
else: | |
response = 'Nonsense' | |
# Open the Google Sheets document | |
sh = gc.open_by_key(sheet_id) | |
worksheet = sh.worksheet(worksheet_name) | |
# Create a DataFrame from the response and additional comments | |
df = pd.DataFrame({'New Input Query': [new_input_query],'Response': [response], 'Additional Comments': [comments]}) | |
# Append the data to the worksheet | |
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"), | |
gr.Textbox(label="New Input Query") | |
], | |
outputs="text" | |
) | |
# Launch the interface | |
feedback_interface.launch() |