desert
commited on
Commit
•
408d189
1
Parent(s):
b2af35c
init inference
Browse files
app.py
CHANGED
@@ -15,36 +15,33 @@ def respond(
|
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
18 |
-
|
19 |
-
|
20 |
-
for
|
21 |
-
if
|
22 |
-
|
23 |
-
if
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
response = ""
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
max_tokens=max_tokens,
|
33 |
stream=True,
|
34 |
temperature=temperature,
|
35 |
top_p=top_p,
|
36 |
):
|
37 |
-
|
38 |
-
|
39 |
-
response += token
|
40 |
yield response
|
41 |
|
42 |
-
|
43 |
"""
|
44 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
"""
|
46 |
demo = gr.ChatInterface(
|
47 |
respond,
|
|
|
48 |
additional_inputs=[
|
49 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
50 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
|
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
18 |
+
# Combine the system message and chat history into a single string
|
19 |
+
prompt = system_message + "\n"
|
20 |
+
for user_input, assistant_reply in history:
|
21 |
+
if user_input:
|
22 |
+
prompt += f"User: {user_input}\n"
|
23 |
+
if assistant_reply:
|
24 |
+
prompt += f"Assistant: {assistant_reply}\n"
|
25 |
+
prompt += f"User: {message}\nAssistant:"
|
26 |
+
|
27 |
+
# Send the request to the model
|
28 |
response = ""
|
29 |
+
for token in client.text_generation(
|
30 |
+
prompt,
|
31 |
+
max_new_tokens=max_tokens,
|
|
|
32 |
stream=True,
|
33 |
temperature=temperature,
|
34 |
top_p=top_p,
|
35 |
):
|
36 |
+
response += token.token
|
|
|
|
|
37 |
yield response
|
38 |
|
|
|
39 |
"""
|
40 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
41 |
"""
|
42 |
demo = gr.ChatInterface(
|
43 |
respond,
|
44 |
+
type="messages",
|
45 |
additional_inputs=[
|
46 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
47 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|