Spaces:
Runtime error
Runtime error
IRB demo
Browse files- CogDebIRB/config.json +12 -0
- CogDebIRB/initial_message.txt +5 -0
- CogDebIRB/system_message.txt +11 -0
- app.py +25 -5
CogDebIRB/config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"wandb_args" : {
|
| 3 |
+
"project": "cogdeb-irb",
|
| 4 |
+
"tags": [
|
| 5 |
+
"demo"
|
| 6 |
+
]
|
| 7 |
+
},
|
| 8 |
+
"model_args" : {
|
| 9 |
+
"model": "gpt-4-1106-preview",
|
| 10 |
+
"temperature": 0.0
|
| 11 |
+
}
|
| 12 |
+
}
|
CogDebIRB/initial_message.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Hello! My name is SurveyGPT, a conversational AI designed to help improve survey research.
|
| 2 |
+
|
| 3 |
+
Please answer the following question:
|
| 4 |
+
|
| 5 |
+
Generally speaking, do you think of yourself as a Republican, a Democrat, an independent, or something else?
|
CogDebIRB/system_message.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are an AI designed to help researchers validate questions before they field their surveys by pre-testing interviews with human respondents.
|
| 2 |
+
Your job is to conduct an interview with the respondent, and to understand as well as possible the question, its wording, and how the human interprets it.
|
| 3 |
+
|
| 4 |
+
Your instructions for conducting the interview are as follows:
|
| 5 |
+
- First, ask the respondent the Cognitive Debrief Question as is.
|
| 6 |
+
- If they have questions about the question, answer these to the best of your ability
|
| 7 |
+
- After they give a response, ask follow-up questions designed to understand how they understand the question and its meaning
|
| 8 |
+
- Do not lead the respondent to a particular answer or suggest answers to the respondent; your goal is to provide an informative transcript that the researcher can review afterwards to help revise their question wording so that new respondents will have the same understanding as intended by the researcher.
|
| 9 |
+
|
| 10 |
+
The question you are testing today is as follows:
|
| 11 |
+
Generally speaking, do you think of yourself as a Republican, a Democrat, an independent, or something else?
|
app.py
CHANGED
|
@@ -13,6 +13,7 @@ Version Log:
|
|
| 13 |
- Azure OpenAI?
|
| 14 |
- 2024.01.31: wandb does not work for use case, what to do instead?
|
| 15 |
- Write to local file and then upload at end? (does filestream cause blocking?)
|
|
|
|
| 16 |
|
| 17 |
"""
|
| 18 |
from __future__ import annotations
|
|
@@ -22,7 +23,7 @@ import logging
|
|
| 22 |
import json
|
| 23 |
import wandb
|
| 24 |
import gradio as gr
|
| 25 |
-
import
|
| 26 |
|
| 27 |
from pathlib import Path
|
| 28 |
|
|
@@ -37,7 +38,7 @@ from utils import (
|
|
| 37 |
|
| 38 |
|
| 39 |
# %% Initialization
|
| 40 |
-
CONFIG_DIR: Path = Path("./
|
| 41 |
if os.environ.get("AZURE_ENDPOINT") is None: # Set Azure credentials from local files
|
| 42 |
seed_azure_key()
|
| 43 |
client = initialize_client()
|
|
@@ -105,6 +106,9 @@ def initialize_tracker(
|
|
| 105 |
def save_interview(
|
| 106 |
chat_history: list[list[str | None]],
|
| 107 |
) -> None:
|
|
|
|
|
|
|
|
|
|
| 108 |
chat_data = []
|
| 109 |
for pair in chat_history:
|
| 110 |
for i, role in enumerate(["user", "bot"]):
|
|
@@ -128,7 +132,7 @@ def bot_message(
|
|
| 128 |
chat_history: list[list[str | None]],
|
| 129 |
system_message: str,
|
| 130 |
model_args: dict[str, str | float],
|
| 131 |
-
) ->
|
| 132 |
# Prep messages
|
| 133 |
user_msg = chat_history[-1][0]
|
| 134 |
messages = convert_gradio_to_openai(chat_history[:-1])
|
|
@@ -168,8 +172,8 @@ def reset_interview() -> (
|
|
| 168 |
|
| 169 |
|
| 170 |
# LAYOUT
|
| 171 |
-
with gr.Blocks() as demo:
|
| 172 |
-
gr.Markdown("#
|
| 173 |
userDisplay = gr.Markdown("", visible=False)
|
| 174 |
|
| 175 |
# Config values
|
|
@@ -203,6 +207,22 @@ with gr.Blocks() as demo:
|
|
| 203 |
visible=False,
|
| 204 |
)
|
| 205 |
resetButton = gr.Button("Save and Exit", visible=False, variant="stop")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
## INTERACTIONS
|
| 208 |
# Start Interview button
|
|
|
|
| 13 |
- Azure OpenAI?
|
| 14 |
- 2024.01.31: wandb does not work for use case, what to do instead?
|
| 15 |
- Write to local file and then upload at end? (does filestream cause blocking?)
|
| 16 |
+
- 2024.03.03: Creating new instance for demoing to IRB
|
| 17 |
|
| 18 |
"""
|
| 19 |
from __future__ import annotations
|
|
|
|
| 23 |
import json
|
| 24 |
import wandb
|
| 25 |
import gradio as gr
|
| 26 |
+
from typing import Generator, Any
|
| 27 |
|
| 28 |
from pathlib import Path
|
| 29 |
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
# %% Initialization
|
| 41 |
+
CONFIG_DIR: Path = Path("./CogDebIRB")
|
| 42 |
if os.environ.get("AZURE_ENDPOINT") is None: # Set Azure credentials from local files
|
| 43 |
seed_azure_key()
|
| 44 |
client = initialize_client()
|
|
|
|
| 106 |
def save_interview(
|
| 107 |
chat_history: list[list[str | None]],
|
| 108 |
) -> None:
|
| 109 |
+
# Save chat_history as json
|
| 110 |
+
with open(CONFIG_DIR/"transcript.json", 'w') as fh:
|
| 111 |
+
json.dump(chat_history, fh, indent=2)
|
| 112 |
chat_data = []
|
| 113 |
for pair in chat_history:
|
| 114 |
for i, role in enumerate(["user", "bot"]):
|
|
|
|
| 132 |
chat_history: list[list[str | None]],
|
| 133 |
system_message: str,
|
| 134 |
model_args: dict[str, str | float],
|
| 135 |
+
) -> Generator[Any, Any, Any]:
|
| 136 |
# Prep messages
|
| 137 |
user_msg = chat_history[-1][0]
|
| 138 |
messages = convert_gradio_to_openai(chat_history[:-1])
|
|
|
|
| 172 |
|
| 173 |
|
| 174 |
# LAYOUT
|
| 175 |
+
with gr.Blocks(theme="sudeepshouche/minimalist") as demo:
|
| 176 |
+
gr.Markdown("# Chat Interview Interface")
|
| 177 |
userDisplay = gr.Markdown("", visible=False)
|
| 178 |
|
| 179 |
# Config values
|
|
|
|
| 207 |
visible=False,
|
| 208 |
)
|
| 209 |
resetButton = gr.Button("Save and Exit", visible=False, variant="stop")
|
| 210 |
+
disclaimer = gr.HTML(
|
| 211 |
+
"""
|
| 212 |
+
<div
|
| 213 |
+
style='font-size: 1em;
|
| 214 |
+
font-style: italic;
|
| 215 |
+
position: fixed;
|
| 216 |
+
left: 50%;
|
| 217 |
+
bottom: 20px;
|
| 218 |
+
transform: translate(-50%, -50%);
|
| 219 |
+
margin: 0 auto;
|
| 220 |
+
'
|
| 221 |
+
>{}</div>
|
| 222 |
+
""".format(
|
| 223 |
+
"Statements by the chatbot may contain factual inaccuracies."
|
| 224 |
+
)
|
| 225 |
+
)
|
| 226 |
|
| 227 |
## INTERACTIONS
|
| 228 |
# Start Interview button
|