Spaces:
Runtime error
Runtime error
Commit
•
b41103a
1
Parent(s):
513e175
Update app.py
Browse files
app.py
CHANGED
@@ -20,12 +20,12 @@ article = """
|
|
20 |
<img src='http://www.simoninithomas.com/test/gandalf.jpg', alt="Gandalf"/>"""
|
21 |
theme="huggingface"
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
# Builds the prompt from what previously happened
|
28 |
-
def build_prompt(conversation, context):
|
29 |
prompt = context + "\n"
|
30 |
for user_msg, resp_msg in conversation:
|
31 |
line = "\n- " + interlocutor_names[0] + ":" + user_msg
|
@@ -36,19 +36,20 @@ def build_prompt(conversation, context):
|
|
36 |
return prompt
|
37 |
|
38 |
# Recognize what the model said, if it used the correct format
|
39 |
-
def clean_chat_output(txt, prompt):
|
40 |
delimiter = "\n- "+interlocutor_names[0]
|
41 |
output = txt.replace(prompt, '')
|
42 |
output = output[:output.find(delimiter)]
|
43 |
return output
|
44 |
|
45 |
|
46 |
-
def chat(top_p, temperature, max_new_tokens
|
|
|
47 |
history = gr.get_state() or []
|
48 |
history.append((message, ""))
|
49 |
gr.set_state(history)
|
50 |
conversation = history
|
51 |
-
prompt = build_prompt(conversation, context)
|
52 |
|
53 |
# Build JSON
|
54 |
json_ = {"inputs": prompt,
|
@@ -62,7 +63,7 @@ def chat(top_p, temperature, max_new_tokens, message):
|
|
62 |
|
63 |
output = query(json_)
|
64 |
output = output[0]['generated_text']
|
65 |
-
answer = clean_chat_output(output, prompt)
|
66 |
response = answer
|
67 |
history[-1] = (message, response)
|
68 |
gr.set_state(history)
|
|
|
20 |
<img src='http://www.simoninithomas.com/test/gandalf.jpg', alt="Gandalf"/>"""
|
21 |
theme="huggingface"
|
22 |
|
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 user_msg, resp_msg in conversation:
|
31 |
line = "\n- " + interlocutor_names[0] + ":" + user_msg
|
|
|
36 |
return prompt
|
37 |
|
38 |
# Recognize what the model said, if it used the correct format
|
39 |
+
def clean_chat_output(txt, prompt, interlocutor_names):
|
40 |
delimiter = "\n- "+interlocutor_names[0]
|
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)
|
51 |
conversation = history
|
52 |
+
prompt = build_prompt(conversation, context, interlocutor_names)
|
53 |
|
54 |
# Build JSON
|
55 |
json_ = {"inputs": prompt,
|
|
|
63 |
|
64 |
output = query(json_)
|
65 |
output = output[0]['generated_text']
|
66 |
+
answer = clean_chat_output(output, prompt, interlocutor_names)
|
67 |
response = answer
|
68 |
history[-1] = (message, response)
|
69 |
gr.set_state(history)
|