Spaces:
Runtime error
Runtime error
Commit
•
e4b4477
1
Parent(s):
e2abd20
Update app.py
Browse files
app.py
CHANGED
@@ -23,14 +23,14 @@ theme="huggingface"
|
|
23 |
|
24 |
|
25 |
|
26 |
-
|
27 |
# Builds the prompt from what previously happened
|
28 |
def build_prompt(conversation, context, interlocutor_names):
|
29 |
prompt = context + "\n"
|
30 |
-
for
|
31 |
-
line = "\n- " + interlocutor_names[0] + ":" +
|
32 |
prompt += line
|
33 |
-
line = "\n- " + interlocutor_names[1] + ":" +
|
34 |
prompt += line
|
35 |
prompt += ""
|
36 |
return prompt
|
@@ -41,10 +41,21 @@ def clean_chat_output(txt, prompt, interlocutor_names):
|
|
41 |
output = txt.replace(prompt, '')
|
42 |
output = output[:output.find(delimiter)]
|
43 |
return output
|
|
|
|
|
44 |
|
45 |
|
46 |
-
def chat(message, npc_name, prompt, top_p, temperature, max_new_tokens):
|
47 |
interlocutor_names = ["Player", npc_name]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
history = gr.get_state() or []
|
49 |
history.append((message, ""))
|
50 |
gr.set_state(history)
|
@@ -67,6 +78,7 @@ def chat(message, npc_name, prompt, top_p, temperature, max_new_tokens):
|
|
67 |
response = answer
|
68 |
history[-1] = (message, response)
|
69 |
gr.set_state(history)
|
|
|
70 |
return response, history
|
71 |
|
72 |
|
@@ -79,7 +91,6 @@ inputs=[Textbox(label="message"),
|
|
79 |
Slider(minimum=0.5, maximum=1, step=0.05, default=0.9, label="top_p"),
|
80 |
Slider(minimum=0.5, maximum=1.5, step=0.1, default=1.1, label="temperature"),
|
81 |
Slider(minimum=20, maximum=250, step=10, default=50, label="max_new_tokens"),
|
82 |
-
"text",
|
83 |
"state"],
|
84 |
outputs=["chatbot","state"],
|
85 |
#examples="",
|
|
|
23 |
|
24 |
|
25 |
|
26 |
+
"""
|
27 |
# Builds the prompt from what previously happened
|
28 |
def build_prompt(conversation, context, interlocutor_names):
|
29 |
prompt = context + "\n"
|
30 |
+
for player_msg, npc_msg in conversation:
|
31 |
+
line = "\n- " + interlocutor_names[0] + ":" + player_msg
|
32 |
prompt += line
|
33 |
+
line = "\n- " + interlocutor_names[1] + ":" + npc_msg
|
34 |
prompt += line
|
35 |
prompt += ""
|
36 |
return prompt
|
|
|
41 |
output = txt.replace(prompt, '')
|
42 |
output = output[:output.find(delimiter)]
|
43 |
return output
|
44 |
+
"""
|
45 |
+
|
46 |
|
47 |
|
48 |
+
def chat(message, npc_name, prompt, top_p, temperature, max_new_tokens, history=[]):
|
49 |
interlocutor_names = ["Player", npc_name]
|
50 |
+
|
51 |
+
print("message", message)
|
52 |
+
print("npc_name", npc_name)
|
53 |
+
print("top_p", top_p)
|
54 |
+
print("temperature", temperature)
|
55 |
+
print("max_new_tokens", max_new_tokens)
|
56 |
+
print("history", history)
|
57 |
+
response = "Test"
|
58 |
+
"""
|
59 |
history = gr.get_state() or []
|
60 |
history.append((message, ""))
|
61 |
gr.set_state(history)
|
|
|
78 |
response = answer
|
79 |
history[-1] = (message, response)
|
80 |
gr.set_state(history)
|
81 |
+
"""
|
82 |
return response, history
|
83 |
|
84 |
|
|
|
91 |
Slider(minimum=0.5, maximum=1, step=0.05, default=0.9, label="top_p"),
|
92 |
Slider(minimum=0.5, maximum=1.5, step=0.1, default=1.1, label="temperature"),
|
93 |
Slider(minimum=20, maximum=250, step=10, default=50, label="max_new_tokens"),
|
|
|
94 |
"state"],
|
95 |
outputs=["chatbot","state"],
|
96 |
#examples="",
|