suhamemon1
commited on
Commit
•
21d6e86
1
Parent(s):
362c439
done
Browse files- __pycache__/model_generate.cpython-311.pyc +0 -0
- __pycache__/utils.cpython-311.pyc +0 -0
- app.py +4 -2
- model_generate.py +5 -10
- utils.py +3 -3
- wraite.png +0 -0
__pycache__/model_generate.cpython-311.pyc
CHANGED
Binary files a/__pycache__/model_generate.cpython-311.pyc and b/__pycache__/model_generate.cpython-311.pyc differ
|
|
__pycache__/utils.cpython-311.pyc
CHANGED
Binary files a/__pycache__/utils.cpython-311.pyc and b/__pycache__/utils.cpython-311.pyc differ
|
|
app.py
CHANGED
@@ -18,7 +18,9 @@ import uuid
|
|
18 |
|
19 |
# radio button and button rendering: https://www.gradio.app/docs/radio
|
20 |
|
21 |
-
with gr.Blocks(title="wrAIte") as demo:
|
|
|
|
|
22 |
questionnaire_results = {
|
23 |
'Demographic Details': {},
|
24 |
'User Capabilities': {},
|
@@ -216,7 +218,7 @@ with gr.Blocks(title="wrAIte") as demo:
|
|
216 |
)
|
217 |
with gr.Column("Question 6", render=True, visible=False) as question6:
|
218 |
next_q6_btn = gr.Button("Next Question", render=False, visible=False, variant="primary")
|
219 |
-
q6 =
|
220 |
q6.render()
|
221 |
next_q6_btn.render()
|
222 |
next_q6_btn.click(
|
|
|
18 |
|
19 |
# radio button and button rendering: https://www.gradio.app/docs/radio
|
20 |
|
21 |
+
with gr.Blocks(title="wrAIte", theme='gradio/soft') as demo:
|
22 |
+
# gr.Image("/file=wraite.png", interactive=False)
|
23 |
+
|
24 |
questionnaire_results = {
|
25 |
'Demographic Details': {},
|
26 |
'User Capabilities': {},
|
|
|
218 |
)
|
219 |
with gr.Column("Question 6", render=True, visible=False) as question6:
|
220 |
next_q6_btn = gr.Button("Next Question", render=False, visible=False, variant="primary")
|
221 |
+
q6 = generate_assisted_question(question_prompts[5], next_q6_btn, 6, question_answers)
|
222 |
q6.render()
|
223 |
next_q6_btn.render()
|
224 |
next_q6_btn.click(
|
model_generate.py
CHANGED
@@ -29,7 +29,6 @@ def query_a_chat_completion(model, messages):
|
|
29 |
|
30 |
|
31 |
def query_chatbot(model, messages):
|
32 |
-
print(messages)
|
33 |
assert model in ["gpt-3.5-turbo", "gpt-4"]
|
34 |
chat_completion = client.chat.completions.create(
|
35 |
messages=messages,
|
@@ -38,7 +37,7 @@ def query_chatbot(model, messages):
|
|
38 |
return chat_completion.choices[0].message.content
|
39 |
|
40 |
|
41 |
-
def chatbot_generate(user_newest_input, history, model,
|
42 |
"""
|
43 |
Generate the next response from the chatbot
|
44 |
:param user_newest_input: The newest input from the user
|
@@ -47,8 +46,6 @@ def chatbot_generate(user_newest_input, history, model, current_answer, initial_
|
|
47 |
:return: The chatbot state, the history, the text, the submit button
|
48 |
"""
|
49 |
# convert to openai model format
|
50 |
-
print('generating chatbot')
|
51 |
-
print()
|
52 |
actual_model = {
|
53 |
"chatgpt4": "gpt-4",
|
54 |
"chatgpt": "gpt-3.5-turbo"
|
@@ -58,18 +55,16 @@ def chatbot_generate(user_newest_input, history, model, current_answer, initial_
|
|
58 |
history.append(f"User: {user_newest_input.strip()}")
|
59 |
|
60 |
# construct chat messages
|
61 |
-
print(initial_txt)
|
62 |
chat_messages = [{"role": "system", "content": initial_txt}]
|
63 |
|
64 |
# chat_messages = [{"role": "system", "content": initial_txt}]
|
65 |
-
current_txt = "My current answer to the instructions is as follows: " + current_answer + '. Now, assist me with the following: '
|
66 |
for hist in history:
|
67 |
if hist.startswith("User:"):
|
68 |
-
content = current_txt + hist[5:].strip()
|
69 |
chat_messages.append(
|
70 |
{
|
71 |
"role": "user",
|
72 |
-
"content":
|
73 |
}
|
74 |
)
|
75 |
elif hist.startswith("Writing Assistant:"):
|
@@ -85,8 +80,8 @@ def chatbot_generate(user_newest_input, history, model, current_answer, initial_
|
|
85 |
|
86 |
# Get the generation from OpenAI
|
87 |
if actual_model in ["gpt-3.5-turbo", "gpt-4"]:
|
88 |
-
print('generating chatbot')
|
89 |
-
print(actual_model)
|
90 |
print(chat_messages)
|
91 |
ai_newest_output = query_chatbot(actual_model, chat_messages)
|
92 |
else:
|
|
|
29 |
|
30 |
|
31 |
def query_chatbot(model, messages):
|
|
|
32 |
assert model in ["gpt-3.5-turbo", "gpt-4"]
|
33 |
chat_completion = client.chat.completions.create(
|
34 |
messages=messages,
|
|
|
37 |
return chat_completion.choices[0].message.content
|
38 |
|
39 |
|
40 |
+
def chatbot_generate(user_newest_input, history, model, initial_txt):
|
41 |
"""
|
42 |
Generate the next response from the chatbot
|
43 |
:param user_newest_input: The newest input from the user
|
|
|
46 |
:return: The chatbot state, the history, the text, the submit button
|
47 |
"""
|
48 |
# convert to openai model format
|
|
|
|
|
49 |
actual_model = {
|
50 |
"chatgpt4": "gpt-4",
|
51 |
"chatgpt": "gpt-3.5-turbo"
|
|
|
55 |
history.append(f"User: {user_newest_input.strip()}")
|
56 |
|
57 |
# construct chat messages
|
|
|
58 |
chat_messages = [{"role": "system", "content": initial_txt}]
|
59 |
|
60 |
# chat_messages = [{"role": "system", "content": initial_txt}]
|
61 |
+
# current_txt = "My current answer to the instructions is as follows: " + current_answer + '. Now, assist me with the following: '
|
62 |
for hist in history:
|
63 |
if hist.startswith("User:"):
|
|
|
64 |
chat_messages.append(
|
65 |
{
|
66 |
"role": "user",
|
67 |
+
"content": hist[5:].strip()
|
68 |
}
|
69 |
)
|
70 |
elif hist.startswith("Writing Assistant:"):
|
|
|
80 |
|
81 |
# Get the generation from OpenAI
|
82 |
if actual_model in ["gpt-3.5-turbo", "gpt-4"]:
|
83 |
+
# print('generating chatbot')
|
84 |
+
# print(actual_model)
|
85 |
print(chat_messages)
|
86 |
ai_newest_output = query_chatbot(actual_model, chat_messages)
|
87 |
else:
|
utils.py
CHANGED
@@ -326,7 +326,7 @@ def generate_assisted_question(question_prompt, next_q_btn, q_num, question_answ
|
|
326 |
|
327 |
conversations_list = []
|
328 |
with gr.Column() as chatbot_col:
|
329 |
-
chatbot = gr.Chatbot(conversations_list, height=
|
330 |
# Chat state
|
331 |
state = gr.State(conversations_list)
|
332 |
initial_usr_msg_state = gr.State(initial_user_message)
|
@@ -338,7 +338,7 @@ def generate_assisted_question(question_prompt, next_q_btn, q_num, question_answ
|
|
338 |
txt = gr.Textbox(
|
339 |
value="",
|
340 |
show_label=False,
|
341 |
-
placeholder="Enter text and press the Interact button",
|
342 |
lines=2,
|
343 |
container=False,
|
344 |
scale=4)
|
@@ -357,7 +357,7 @@ def generate_assisted_question(question_prompt, next_q_btn, q_num, question_answ
|
|
357 |
autofocus=True,
|
358 |
label="Write your response here:")
|
359 |
|
360 |
-
submit_button.click(chatbot_generate, [txt, state, model_state,
|
361 |
|
362 |
text_button2 = gr.Button("Submit Response", variant="primary", interactive=False)
|
363 |
tab_text2.input(count_words, tab_text2, [text_button2, word_count], show_progress="hidden")
|
|
|
326 |
|
327 |
conversations_list = []
|
328 |
with gr.Column() as chatbot_col:
|
329 |
+
chatbot = gr.Chatbot(conversations_list, height=350, label="Writing Helper")
|
330 |
# Chat state
|
331 |
state = gr.State(conversations_list)
|
332 |
initial_usr_msg_state = gr.State(initial_user_message)
|
|
|
338 |
txt = gr.Textbox(
|
339 |
value="",
|
340 |
show_label=False,
|
341 |
+
placeholder="Enter text and press the Interact button. Your current answer will not be sent to the assistant. If you want the assistant to know your current answer, paste it into the chat window.",
|
342 |
lines=2,
|
343 |
container=False,
|
344 |
scale=4)
|
|
|
357 |
autofocus=True,
|
358 |
label="Write your response here:")
|
359 |
|
360 |
+
submit_button.click(chatbot_generate, [txt, state, model_state, initial_usr_msg_state], [chatbot, state, txt, submit_button])
|
361 |
|
362 |
text_button2 = gr.Button("Submit Response", variant="primary", interactive=False)
|
363 |
tab_text2.input(count_words, tab_text2, [text_button2, word_count], show_progress="hidden")
|
wraite.png
ADDED