langdonholmes commited on
Commit
6554910
Β·
1 Parent(s): 8923936
Files changed (5) hide show
  1. .gitignore +2 -0
  2. README.md +1 -1
  3. app.py +150 -0
  4. botresponse-6f1a8c749aa0.json +14 -0
  5. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .venv
2
+ .devcontainer
README.md CHANGED
@@ -10,4 +10,4 @@ pinned: false
10
  license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
10
  license: mit
11
  ---
12
 
13
+ We are using this to evaluate our intelligent tutor. Please provide feedback on the bot's response to your question.
app.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import gspread
4
+ from google.auth import default
5
+ import requests
6
+ import time
7
+ import json
8
+ import re
9
+
10
+ # Authenticate and authorize with Google Sheets
11
+ # creds, _ = default()
12
+ # gc = gspread.authorize(creds)
13
+ gc = gspread.service_account(filename="botresponse-6f1a8c749aa0.json")
14
+
15
+ # Specify your Google Sheets credentials, sheet_id, and worksheet_name
16
+ sheet_id = "18hnoTsEaGMWMael42MXubb-FzAe5jJB5RpaSolIXyb0"
17
+ worksheet_name = "Sheet1"
18
+
19
+
20
+ # Function to get the initial response
21
+ def get_initial_response(input_message):
22
+ url = "https://itell-api.learlab.vanderbilt.edu/chat"
23
+
24
+ payload = {"textbook_name": "think-python-2e", "message": input_message}
25
+ headers = {"Content-Type": "application/json"}
26
+
27
+ # Measure the start time
28
+ start_time = time.time()
29
+
30
+ response = requests.post(url, json=payload, headers=headers)
31
+ data = json.loads(response.text)
32
+ message = data["message"]
33
+ message = message.encode("utf-8").decode("unicode_escape")
34
+ message = re.sub(r"^[\s'\"]*(bot|cite sources)?[\s'\"]*", "", message)
35
+ message = message.strip(" ':\"")
36
+
37
+ # Calculate the elapsed time
38
+ elapsed_time = time.time() - start_time
39
+ elapsed_time = round(elapsed_time, 2)
40
+
41
+ return {
42
+ bot_resp: message,
43
+ response_time: elapsed_time,
44
+ }
45
+
46
+
47
+ # Function to collect feedback and update the spreadsheet
48
+ def feedback_response(
49
+ input_message,
50
+ bot_message,
51
+ response_time,
52
+ feedback_primary,
53
+ feedback_secondary,
54
+ comments,
55
+ ):
56
+ # Update Google Sheets
57
+ sh = gc.open_by_key(sheet_id)
58
+ worksheet = sh.worksheet(worksheet_name)
59
+
60
+ # Create a DataFrame from the response and additional comments
61
+ df = pd.DataFrame(
62
+ {
63
+ "Input Message": [input_message],
64
+ "Output": [bot_message],
65
+ "Time took in Seconds": [response_time],
66
+ "Initial Feedback": [feedback_primary],
67
+ "Secondary Feedback": [str(feedback_secondary)],
68
+ "Additional Comments": [comments],
69
+ }
70
+ )
71
+
72
+ # Append the data to the worksheet
73
+ worksheet.append_rows(df.values.tolist())
74
+ gr.Info("Feedback Submitted")
75
+ return {
76
+ primary_feedback: None,
77
+ secondary_feedback: None,
78
+ additional_comments: None,
79
+ }
80
+
81
+
82
+ with gr.Blocks(title="iTELL Chat Feedback") as feedback_interface:
83
+ title = "Itell Guide Response Bot"
84
+ gr.components.Markdown(
85
+ f"<h1 style='text-align: center; margin-bottom: 1rem'>{title}</h1>"
86
+ )
87
+ gr.Markdown(
88
+ """
89
+ # Introduction
90
+ This is an interface to test iTELL's guide on the side. Please be aware that responses can take up to 20 seconds.
91
+ # Step by Step Introduction
92
+ 1. Place a question in the input message textbox.
93
+ 2. Wait 10 ~ 20 seconds for the response to appear on the right.
94
+ 3. After looking at the results, provide primary feedback on the response.
95
+ 4. If desired, add secondary feedback selections: Informative, Inaccurate, Nonsense.
96
+ 4. Write down additional comments for more feedback.
97
+ 5. Press "Submit Feedback".
98
+ """
99
+ )
100
+ elapsed_time = gr.State(0)
101
+ with gr.Row():
102
+ with gr.Column():
103
+ usr_msg = gr.Textbox(interactive=True, label="Input Message", lines=7)
104
+ response_time = gr.Number(label="Response Time", step=0.01)
105
+ bot_resp = gr.Textbox(label="Output", type="text", lines=10)
106
+ with gr.Row():
107
+ clear_btn = gr.ClearButton(usr_msg, value="Clear")
108
+ submit_btn = gr.Button("Submit")
109
+ # submit_btn.click(get_initial_response, inputs=usr_msg, outputs=bot_resp)
110
+ with gr.Column():
111
+ primary_feedback = gr.Radio(
112
+ ["πŸ‘ good", "πŸ‘Ž bad", "❌ inappropriate"], label="Primary Feedback"
113
+ )
114
+ secondary_feedback = gr.CheckboxGroup(
115
+ [
116
+ "🧠 Informative",
117
+ "πŸ™… Inaccurate",
118
+ "❓ Nonsense",
119
+ "🩢 Character Encoding Error",
120
+ ],
121
+ label="Secondary Feedback",
122
+ )
123
+ additional_comments = gr.Textbox(
124
+ label="Additional Comments", interactive=True, lines=7
125
+ )
126
+ feedback_btn = gr.Button("Submit Feedback")
127
+ feedback_btn.click(
128
+ feedback_response,
129
+ inputs=[
130
+ usr_msg,
131
+ bot_resp,
132
+ response_time,
133
+ primary_feedback,
134
+ secondary_feedback,
135
+ additional_comments,
136
+ ],
137
+ outputs=[
138
+ primary_feedback,
139
+ secondary_feedback,
140
+ additional_comments
141
+ ],
142
+ )
143
+ submit_btn.click(
144
+ fn=get_initial_response,
145
+ inputs=usr_msg,
146
+ outputs=[bot_resp, response_time],
147
+ )
148
+
149
+ # Launch the interface
150
+ feedback_interface.launch()
botresponse-6f1a8c749aa0.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "type": "service_account",
3
+ "project_id": "botresponse",
4
+ "private_key_id": "6f1a8c749aa053d284e56189b1755be1ca485963",
5
+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCq3KAHkFP+/QWN\nphPc5g6DzbaPe1uhkH7gVBHeXSsA+moYs1gcNMWOWXHGmvmQOiOQCeacF4LXEk+f\nHg9xQm5fq32Td4ZuBHW5R24+iNj7MT+3sTo7Ru5eiMc9Mig1WTig3DPKbsEnZ/Av\nkpqERtoQTo7AWkD1iN0Dhl9vQlGzB3npYkNXv/o5KW/Gx/YlzQ2CvDm17VCgGecM\n+MfsAgzfgS++MXDGrj4AnP/XNMNLshpr8TO5CiMzbTey7gkDFMrTxcfFQXsE9fcc\n/y8327ZwKEjm0ycsE+49u2yhei6kbE+TRkWnHP50Ocno9oGAwn0Td/8M9uxXEBPL\n25O3RQE3AgMBAAECggEACU2vFwpYUIOVeFOJNFeAhdO/M4vbfu4fwnZBbNK04z4/\nZa3qR8rl0Oz04YQRv7Uyt4aafHhZQv23wSnBXIDqAqKTWWLCOp5ajKajjZsk+XSC\njC2FxrGDjDk1ZBMlllYP285xsX2bXdpufSCl8jrrZ8TnR/kCHXyA0E7SRnwdd7qD\nJSEOnX3afNfSA/ajK2rFjid5pRCI7piLn8gvCxi/YXtBCI2CX02ZryuTFYu7FXu/\nHfXdjcFmjpsiU+4CpExnJr5f7BB8R4Yq69qDjHXhSDj7qaLNFW2cY+gO4Guc4szV\nJoYWGTQEjlYkGpkhMlkpjbrXNGyNM/x3PXOF+9Q4YQKBgQDhhHKdonCxCQQQb4JN\n8gtUhk6lsF5oe29OtTvp0qG+kv/WPhb+PNnVw/VHQUooZA+YJDZQq+ykCzCMW+Yw\n0wqJ1QBBPc80XAqO3AUJN5XupgCwkkrirStoV5Vwc0+KF+72e/vTZGZVP55DkCZo\np0x21oJ/ugjhV0XW6aFBm1atIQKBgQDB9O/z3TwPtg9uNNOVL/6hfzSq+awtLrYh\nFt0gb/reZ90smxL0wgDQfWqwXOW3sU4He/42eY0+TgeWWg4nAaherz9KTwfKerAM\nGpDOltJV0z8ZBWgvPp3IwiOiHSEdiuVNFcRt73z234wIklSmNl94M/adLyZQHeh+\n0VB+IafLVwKBgQDH80IYR9146hCDbgrvhyrKj6aNu5mJM+AVvhTYFVw5d2aEk1qZ\nomRV5z/DJL1WoJk/AORzlGvlatJpsFWhdozCdmuabO4Zc34c+jEw4er6xI6Z/6uL\n3ZQ+GGG0aVjdjKjgPD+kR0GAVj7Bkr6rTaI7P6hHDTAwc8vFaDIE1HD+YQKBgHhU\nkKW35LJOnkYeKgJNk2j4NWG5olMpvr7Ko4ejUX237GTnFJya28x9crpV+AK90o4c\nI/wB71nvKQ/jcRJMGfwcN2TPoSLCeQQZWyuAMKAkfen1C8z7yQIrR9Ykwk3ExTvM\nvGAEC4BR8lvDBRdVdmdpvZ+JB/j+hSZgj9Kg6KvjAoGAaqpvA9VxTiJGwHspw0mx\nCiHJu+J9h7sL1knTWjUxzftFVjDPggs0hYt7sf7Aj6s+4MvPkiJW/MXBra6pBHPY\nHLi69+5h6KJKcQSlCEx6jfk7R3vTYo7BMl0Z1o8/LIrOFeZ6+BCXmk2HFOgr5AzO\nOvg/P2OQJkKBbb3lz7drYEw=\n-----END PRIVATE KEY-----\n",
6
+ "client_email": "botresponse@botresponse.iam.gserviceaccount.com",
7
+ "client_id": "107407555109034862305",
8
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
9
+ "token_uri": "https://oauth2.googleapis.com/token",
10
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/botresponse%40botresponse.iam.gserviceaccount.com",
12
+ "universe_domain": "googleapis.com"
13
+ }
14
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio >=3.45.0
2
+ gspread