Spaces:
Runtime error
Runtime error
Aakash Vardhan
commited on
Commit
·
e6c656b
1
Parent(s):
c4cedc2
app.py
CHANGED
@@ -42,13 +42,23 @@ def respond(
|
|
42 |
temperature,
|
43 |
top_p,
|
44 |
):
|
45 |
-
# Construct the
|
46 |
-
|
47 |
for user, assistant in history:
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
response = ""
|
53 |
for output in pipe(
|
54 |
prompt,
|
@@ -56,9 +66,11 @@ def respond(
|
|
56 |
do_sample=True,
|
57 |
temperature=temperature,
|
58 |
top_p=top_p,
|
59 |
-
|
|
|
|
|
60 |
):
|
61 |
-
new_text = output[0][
|
62 |
response += new_text
|
63 |
yield response.strip()
|
64 |
|
@@ -81,7 +93,7 @@ demo = gr.ChatInterface(
|
|
81 |
label="System message",
|
82 |
),
|
83 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
84 |
-
gr.Slider(minimum=0.1, maximum=
|
85 |
gr.Slider(
|
86 |
minimum=0.1,
|
87 |
maximum=1.0,
|
@@ -90,6 +102,8 @@ demo = gr.ChatInterface(
|
|
90 |
label="Top-p (nucleus sampling)",
|
91 |
),
|
92 |
],
|
|
|
|
|
93 |
)
|
94 |
|
95 |
|
|
|
42 |
temperature,
|
43 |
top_p,
|
44 |
):
|
45 |
+
# Construct the chat list
|
46 |
+
chat_list = [{"role": "system", "content": system_message}]
|
47 |
for user, assistant in history:
|
48 |
+
chat_list.extend(
|
49 |
+
[
|
50 |
+
{"role": "user", "content": user},
|
51 |
+
{"role": "assistant", "content": assistant},
|
52 |
+
]
|
53 |
+
)
|
54 |
+
chat_list.append({"role": "user", "content": message})
|
55 |
+
|
56 |
+
# Apply chat template
|
57 |
+
prompt = pipe.tokenizer.apply_chat_template(
|
58 |
+
chat_list, tokenize=False, add_generation_prompt=True
|
59 |
+
)
|
60 |
+
|
61 |
+
# Generate response with streaming
|
62 |
response = ""
|
63 |
for output in pipe(
|
64 |
prompt,
|
|
|
66 |
do_sample=True,
|
67 |
temperature=temperature,
|
68 |
top_p=top_p,
|
69 |
+
num_beams=1,
|
70 |
+
top_k=50,
|
71 |
+
streamer=gr.utils.Iteratorize(),
|
72 |
):
|
73 |
+
new_text = output[0]['generated_text'][len(prompt) + len(response):]
|
74 |
response += new_text
|
75 |
yield response.strip()
|
76 |
|
|
|
93 |
label="System message",
|
94 |
),
|
95 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
96 |
+
gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature"),
|
97 |
gr.Slider(
|
98 |
minimum=0.1,
|
99 |
maximum=1.0,
|
|
|
102 |
label="Top-p (nucleus sampling)",
|
103 |
),
|
104 |
],
|
105 |
+
title="General Knowledge Assistant",
|
106 |
+
description="Ask me anything about general knowledge. I'll try to answer succinctly using first principles.",
|
107 |
)
|
108 |
|
109 |
|