jcho02 commited on
Commit
658dc36
β€’
1 Parent(s): 35d6db8
Files changed (4) hide show
  1. .devcontainer/devcontainer.json +26 -0
  2. .gitignore +1 -0
  3. README.md +1 -1
  4. app.py +122 -68
.devcontainer/devcontainer.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the
2
+ // README at: https://github.com/devcontainers/templates/tree/main/src/python
3
+ {
4
+ "name": "Python 3",
5
+ // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6
+ "image": "mcr.microsoft.com/devcontainers/python:1-3.10-bookworm",
7
+ "features": {
8
+ "ghcr.io/devcontainers/features/git:1": {},
9
+ "ghcr.io/devcontainers/features/github-cli:1": {}
10
+ }
11
+
12
+ // Features to add to the dev container. More info: https://containers.dev/features.
13
+ // "features": {},
14
+
15
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
16
+ // "forwardPorts": [],
17
+
18
+ // Use 'postCreateCommand' to run commands after the container is created.
19
+ // "postCreateCommand": "pip3 install --user -r requirements.txt",
20
+
21
+ // Configure tool-specific properties.
22
+ // "customizations": {},
23
+
24
+ // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
25
+ // "remoteUser": "root"
26
+ }
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .devcontainer
README.md CHANGED
@@ -9,4 +9,4 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
9
  pinned: false
10
  ---
11
 
12
+ We are using this to evaluate our intelligent tutor. Please provide feedback on the bot's response to your question.
app.py CHANGED
@@ -3,26 +3,25 @@ import pandas as pd
3
  import gspread
4
  from google.auth import default
5
  import requests
6
- import time
7
  import json
 
8
 
9
  # Authenticate and authorize with Google Sheets
10
- #creds, _ = default()
11
- #gc = gspread.authorize(creds)
12
- gc = gspread.service_account(filename='botresponse-6f1a8c749aa0.json')
13
-
14
  # Specify your Google Sheets credentials, sheet_id, and worksheet_name
15
  sheet_id = "18hnoTsEaGMWMael42MXubb-FzAe5jJB5RpaSolIXyb0"
16
  worksheet_name = "Sheet1"
17
 
 
18
  # Function to get the initial response
19
  def get_initial_response(input_message):
20
  url = "https://itell-api.learlab.vanderbilt.edu/chat"
21
 
22
- payload = {
23
- "textbook_name": "think-python-2e",
24
- "message": input_message
25
- }
26
  headers = {"Content-Type": "application/json"}
27
 
28
  # Measure the start time
@@ -30,81 +29,136 @@ def get_initial_response(input_message):
30
 
31
  response = requests.post(url, json=payload, headers=headers)
32
  data = json.loads(response.text)
33
- message = data['message']
 
 
 
34
 
35
  # Calculate the elapsed time
36
  elapsed_time = time.time() - start_time
37
  elapsed_time = round(elapsed_time, 2)
38
- response_time_message = f"Response time: {elapsed_time} seconds"
39
 
40
- return message, response_time_message # Return the initial_response and elapsed_time
 
 
 
 
41
 
42
  # Function to collect feedback and update the spreadsheet
43
- def feedback_response(input_message, feedback, comments):
44
- # Get the initial response and elapsed_time
45
- initial_response, elapsed_time = get_initial_response(input_message)
46
-
47
- # Collect feedback
48
- response = ''
49
- if feedback == 'Informative':
50
- response = 'Informative'
51
- elif feedback == 'Inaccurate':
52
- response = 'Inaccurate'
53
- elif feedback == 'Nonsense':
54
- response = 'Nonsense'
55
- else:
56
- response = 'NA'
57
 
58
  # Update Google Sheets
59
  sh = gc.open_by_key(sheet_id)
60
  worksheet = sh.worksheet(worksheet_name)
61
-
62
- thankyou = "Thank you for your feedback. Your response and feedback has been recorded!"
63
- # Append the data to the worksheet only if comments have a value
64
- if comments:
65
- # Create a DataFrame from the response and additional comments
66
- df = pd.DataFrame({'Input Message': [input_message], 'Output': [initial_response], 'Time took in Seconds': [elapsed_time],'Feedback': [response], 'Additional Comments': [comments]})
67
 
68
- # Append the data to the worksheet
69
- worksheet.append_rows(df.values.tolist())
70
- initial_response = thankyou
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
 
 
 
72
 
73
- return initial_response, elapsed_time # Return the initial_response and elapsed_time
74
-
75
- # Set up the Gradio Interface
76
- feedback_interface = gr.Interface(
77
- fn=feedback_response,
78
- inputs=[
79
- gr.Textbox(label="Input Message"),
80
- gr.Radio(
81
- choices=[
82
- "Informative",
83
- "Inaccurate",
84
- "Nonsense"
85
- ],
86
- label="Feedback"),
87
- gr.Textbox(label="Additional Comments")
88
- ],
89
- outputs=[
90
- gr.Textbox(label="Output", type="text"),
91
- gr.Textbox(label="Elapsed Time (s)", type="text") # Change the type to "text" for two decimal places
92
- ],
93
- title="Beta: Itell Guide Response Bot",
94
- description="""
95
  # Introduction
96
- This is an interface to test iTELL's guide on the side. Please be aware that responses can take up to 20 seconds
97
  # Step by Step Introduction
98
- 1. Place a question in the input message textbox
99
- 2. Wait roughly 10 ~ 20 seconds for the response and elapsed time to come out on the right
100
- 3. After looking at the results, click on the feedback options that best describes the output: Informative, Inaccurate, Nonsense
101
- 4. After choosing the best option, write down additional comments for more feedback
102
- 5. Press submit again and wait for the output to come out again for your feedback to be submitted
103
- 6. Once the "Thank you for your feedback. Your response and feedback has been recorded!" message is shown, you are done
104
- ** DISCLAIMER: You have to type a input message, click on the feedback buttons, and type in additional comments for your responses to be recorded
105
- ** For further questions contact LEAR Labs!
106
  """
107
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
  # Launch the interface
110
- feedback_interface.launch()
 
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
 
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)?[\s'\"]*(cite sources)?", "", 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
+ feedback = []
57
+ feedback.append(feedback_primary)
58
+ feedback.extend(feedback_secondary)
 
 
 
59
 
60
  # Update Google Sheets
61
  sh = gc.open_by_key(sheet_id)
62
  worksheet = sh.worksheet(worksheet_name)
 
 
 
 
 
 
63
 
64
+ # Create a DataFrame from the response and additional comments
65
+ df = pd.DataFrame(
66
+ {
67
+ "Input Message": [input_message],
68
+ "Output": [bot_message],
69
+ "Time took in Seconds": [response_time],
70
+ "Feedback": [str(feedback)],
71
+ # Jaewoo, I'd prefer to have the feedback split into separate columns
72
+ # You would need to update the spreadsheet for this. Some of the above
73
+ # code could also be deleted.
74
+ # "Primary Feedback": [feedback_primary],
75
+ # "Informative": [True if any("Informative" in s for s in feedback_secondary) else False],
76
+ # "Inaccurate": [True if any("Inaccurate" in s for s in feedback_secondary) else False],
77
+ # "Nonsense": [True if any("Nonsense" in s for s in feedback_secondary) else False],
78
+ # "Encoding": [True if any("Encoding" in s for s in feedback_secondary) else False],
79
+ "Additional Comments": [comments],
80
+ }
81
+ )
82
 
83
+ # Append the data to the worksheet
84
+ worksheet.append_rows(df.values.tolist())
85
+ gr.Info("Feedback Submitted")
86
 
87
+ # Clear the feedback fields
88
+ return {
89
+ primary_feedback: None,
90
+ secondary_feedback: None,
91
+ additional_comments: None,
92
+ }
93
+
94
+
95
+ with gr.Blocks(title="iTELL Chat Feedback") as feedback_interface:
96
+ title = "iTELL Chat Safety Testing"
97
+ gr.components.Markdown(
98
+ f"<h1 style='text-align: center; margin-bottom: 1rem'>{title}</h1>"
99
+ )
100
+ gr.Markdown(
101
+ """
 
 
 
 
 
 
 
102
  # Introduction
103
+ This is an interface to test iTELL's guide on the side. Please be aware that responses can take up to 20 seconds.
104
  # Step by Step Introduction
105
+ 1. Place a question in the input message textbox.
106
+ 2. Wait 10 ~ 20 seconds for the response to appear on the right.
107
+ 3. After looking at the results, provide primary feedback on the response.
108
+ 4. If desired, add secondary feedback selections: Informative, Inaccurate, Nonsense.
109
+ 4. Write down additional comments for more feedback.
110
+ 5. Press "Submit Feedback".
 
 
111
  """
112
+ )
113
+ elapsed_time = gr.State(0)
114
+ with gr.Row():
115
+ with gr.Column():
116
+ usr_msg = gr.Textbox(interactive=True, label="Input Message", lines=7)
117
+ response_time = gr.Number(label="Response Time", step=0.01)
118
+ bot_resp = gr.Textbox(label="Output", type="text", lines=10)
119
+ with gr.Row():
120
+ clear_btn = gr.ClearButton(usr_msg, value="Clear")
121
+ submit_btn = gr.Button("Submit")
122
+ # submit_btn.click(get_initial_response, inputs=usr_msg, outputs=bot_resp)
123
+ with gr.Column():
124
+ primary_feedback = gr.Radio(
125
+ ["πŸ‘ good", "πŸ‘Ž bad", "❌ inappropriate"], label="Primary Feedback"
126
+ )
127
+ secondary_feedback = gr.CheckboxGroup(
128
+ [
129
+ "🧠 Informative",
130
+ "πŸ™… Inaccurate",
131
+ "❓ Nonsense",
132
+ "🩢 Character Encoding Error",
133
+ ],
134
+ label="Secondary Feedback",
135
+ )
136
+ additional_comments = gr.Textbox(
137
+ label="Additional Comments", interactive=True, lines=7
138
+ )
139
+ feedback_btn = gr.Button("Submit Feedback")
140
+ feedback_btn.click(
141
+ feedback_response,
142
+ inputs=[
143
+ usr_msg,
144
+ bot_resp,
145
+ response_time,
146
+ primary_feedback,
147
+ secondary_feedback,
148
+ additional_comments,
149
+ ],
150
+ outputs=[
151
+ primary_feedback,
152
+ secondary_feedback,
153
+ additional_comments
154
+ ],
155
+ )
156
+ gr.on(
157
+ triggers=[submit_btn.click, usr_msg.submit],
158
+ fn=get_initial_response,
159
+ inputs=usr_msg,
160
+ outputs=[bot_resp, response_time],
161
+ )
162
 
163
  # Launch the interface
164
+ feedback_interface.launch()