File size: 1,619 Bytes
c5db237
 
 
 
 
90a2290
12f9952
 
 
90a2290
 
 
 
 
eee1bdc
c5db237
9c69cf4
 
 
 
c5db237
9c69cf4
8d67862
 
c5db237
 
8d67862
eee1bdc
e3d1482
8d67862
 
7d91dc5
8d67862
c5db237
 
 
 
 
 
 
 
 
 
 
 
 
 
9955b8a
 
c5db237
eee1bdc
c5db237
 
 
eee1bdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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()