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): response = '' if feedback == 'Good Response': response = 'Good Response!' elif feedback == 'Bad Response': response = 'Bad Response' else: response = 'Inappropriate response!' if comments: comments = comments # Open the Google Sheets document sh = gc.open_by_key(sheet_id) worksheet = sh.worksheet(worksheet_name) # Create a DataFrame from the response df = pd.DataFrame({'Response': [response],'Additional Comments': [comments]}) # Append the data to the worksheet worksheet.append_table(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()