Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,52 +10,53 @@ client = OpenAI(
|
|
10 |
)
|
11 |
|
12 |
# Initialize the chat log
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
def api_call(prompt):
|
17 |
-
completion = client.chat.completions.create(
|
18 |
-
model=MODEL_ID,
|
19 |
-
messages=[
|
20 |
-
{
|
21 |
-
"role": "user",
|
22 |
-
"content": prompt,
|
23 |
-
},
|
24 |
-
],
|
25 |
-
)
|
26 |
-
answer = completion.choices[0].message.content
|
27 |
-
return answer
|
28 |
-
|
29 |
-
def generate_next(intro, setting, topic, student_identity, teacher_identity, student_base, teacher_base):
|
30 |
-
|
31 |
-
dialog_prev = "\n\n".join(dialog_state)
|
32 |
-
|
33 |
-
# STUDENT
|
34 |
-
student_start = "Basierend auf diesen Vorgaben, überlege, wie der Schüler den Dialog starten würde und schreibe einen realistischen ersten Satz des Schülers. Nutze folgendes Format S: <Schüler Antwort>"
|
35 |
-
prompt_student = intro+"\n\Verlauf des Dialogs: "+setting+"\n\nThema, bei dem der Schüler Hilfe braucht:"+topic+"\n\nBeschreibung des Schülers:"+student_identity+"\n\nBeschreibung des Tutors:"+teacher_identity+"\n\nBisheriger Dialog:\n"+dialog_prev+"\n\n"
|
36 |
-
if len(dialog) == 0:
|
37 |
-
prompt_student+=student_start
|
38 |
-
else:
|
39 |
-
prompt_student+=student_base
|
40 |
-
student = api_call(prompt_student)
|
41 |
-
dialog_state.append(student)
|
42 |
-
dialog_prev = "\n\n".join(dialog_state)
|
43 |
-
|
44 |
-
# TEACHER
|
45 |
-
prompt_teacher = intro+"\n\Verlauf des Dialogs: "+setting+"\n\nThema, bei dem der Schüler Hilfe braucht:"+topic+"\n\nBeschreibung des Schülers:"+student_identity+"\n\nBeschreibung des Tutors:"+teacher_identity+"\n\nBisheriger Dialog:\n"+dialog_prev+"\n\n"+teacher_base
|
46 |
-
teacher = api_call(prompt_teacher)
|
47 |
-
dialog_state.append(teacher)
|
48 |
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
with gr.Blocks() as app:
|
59 |
|
60 |
# Text boxes for user inputs
|
61 |
txt_intro = gr.Textbox(label="Einleitung", lines=4, value = "Ich möchte einen möglichst realistischen Dialog zwischen einem Schüler und einem Tutor simulieren.")
|
@@ -77,8 +78,8 @@ with gr.Blocks() as app:
|
|
77 |
# Define the layout and how components interact
|
78 |
btn_submit.click(
|
79 |
fn=generate_next,
|
80 |
-
inputs=[txt_intro, txt_setting, txt_topic, txt_student_identity, txt_teacher_identity, txt_student_base, txt_teacher_base],
|
81 |
-
outputs=[prompt_student,prompt_teacher, chat_interface],
|
82 |
)
|
83 |
|
84 |
|
|
|
10 |
)
|
11 |
|
12 |
# Initialize the chat log
|
13 |
+
with gr.Blocks() as app:
|
14 |
+
dialog = []
|
15 |
+
dialog_state_var = gr.State([])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
def api_call(prompt):
|
18 |
+
completion = client.chat.completions.create(
|
19 |
+
model=MODEL_ID,
|
20 |
+
messages=[
|
21 |
+
{
|
22 |
+
"role": "user",
|
23 |
+
"content": prompt,
|
24 |
+
},
|
25 |
+
],
|
26 |
+
)
|
27 |
+
answer = completion.choices[0].message.content
|
28 |
+
return answer
|
29 |
|
30 |
+
def generate_next(intro, setting, topic, student_identity, teacher_identity, student_base, teacher_base, dialog_state):
|
31 |
+
|
32 |
+
dialog_prev = "\n\n".join(dialog_state)
|
33 |
+
|
34 |
+
# STUDENT
|
35 |
+
student_start = "Basierend auf diesen Vorgaben, überlege, wie der Schüler den Dialog starten würde und schreibe einen realistischen ersten Satz des Schülers. Nutze folgendes Format S: <Schüler Antwort>"
|
36 |
+
prompt_student = intro+"\n\Verlauf des Dialogs: "+setting+"\n\nThema, bei dem der Schüler Hilfe braucht:"+topic+"\n\nBeschreibung des Schülers:"+student_identity+"\n\nBeschreibung des Tutors:"+teacher_identity+"\n\nBisheriger Dialog:\n"+dialog_prev+"\n\n"
|
37 |
+
if len(dialog) == 0:
|
38 |
+
prompt_student+=student_start
|
39 |
+
else:
|
40 |
+
prompt_student+=student_base
|
41 |
+
student = api_call(prompt_student)
|
42 |
+
dialog_state.append(student)
|
43 |
+
dialog_prev = "\n\n".join(dialog_state)
|
44 |
|
45 |
+
# TEACHER
|
46 |
+
prompt_teacher = intro+"\n\Verlauf des Dialogs: "+setting+"\n\nThema, bei dem der Schüler Hilfe braucht:"+topic+"\n\nBeschreibung des Schülers:"+student_identity+"\n\nBeschreibung des Tutors:"+teacher_identity+"\n\nBisheriger Dialog:\n"+dialog_prev+"\n\n"+teacher_base
|
47 |
+
teacher = api_call(prompt_teacher)
|
48 |
+
dialog_state.append(teacher)
|
49 |
+
|
50 |
+
dialog_new = "\n\n".join(dialog_state)
|
51 |
+
|
52 |
+
return prompt_student,prompt_teacher, dialog_new, dialog_state
|
53 |
+
|
54 |
+
|
55 |
+
def reset():
|
56 |
+
dialog = []
|
57 |
+
|
58 |
+
|
59 |
|
|
|
60 |
|
61 |
# Text boxes for user inputs
|
62 |
txt_intro = gr.Textbox(label="Einleitung", lines=4, value = "Ich möchte einen möglichst realistischen Dialog zwischen einem Schüler und einem Tutor simulieren.")
|
|
|
78 |
# Define the layout and how components interact
|
79 |
btn_submit.click(
|
80 |
fn=generate_next,
|
81 |
+
inputs=[txt_intro, txt_setting, txt_topic, txt_student_identity, txt_teacher_identity, txt_student_base, txt_teacher_base, dialog_state_var],
|
82 |
+
outputs=[prompt_student,prompt_teacher, chat_interface, dialog_state_var],
|
83 |
)
|
84 |
|
85 |
|