Update app.py
Browse files
app.py
CHANGED
@@ -18,36 +18,47 @@ def respond(
|
|
18 |
temperature,
|
19 |
top_p,
|
20 |
):
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
# Create the Gradio interface
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
)
|
45 |
-
msg.submit(
|
46 |
-
respond,
|
47 |
-
inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p],
|
48 |
-
outputs=[chatbot],
|
49 |
-
)
|
50 |
-
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
demo.launch()
|
|
|
18 |
temperature,
|
19 |
top_p,
|
20 |
):
|
21 |
+
history = history[-3:]
|
22 |
+
# Construct the prompt
|
23 |
+
prompt = f"<s>{system_message}\n\n"
|
24 |
+
for user_msg, assistant_msg in history:
|
25 |
+
prompt += f"<|user|>{user_msg}<|end|></s> <|assistant|>{assistant_msg}<|end|></s>"
|
26 |
+
prompt += f"<|user|>{message}<|end|></s> <|assistant|>"
|
27 |
|
28 |
+
# Generate response
|
29 |
+
response = ""
|
30 |
+
for token in model(
|
31 |
+
prompt,
|
32 |
+
max_tokens=max_tokens,
|
33 |
+
temperature=temperature,
|
34 |
+
top_p=top_p,
|
35 |
+
stream=True,
|
36 |
+
stop=["<|end|>", "</s>"]
|
37 |
+
):
|
38 |
+
response += token['choices'][0]['text']
|
39 |
+
yield response.strip()
|
40 |
+
|
41 |
# Create the Gradio interface
|
42 |
+
demo = gr.ChatInterface(
|
43 |
+
respond,
|
44 |
+
undo_btn="Отменить",
|
45 |
+
clear_btn="Очистить",
|
46 |
+
additional_inputs=[
|
47 |
+
# gr.Textbox(value="You are a friendly medical assistant.", label="System message"),
|
48 |
+
gr.Textbox(value="", label="System message"),
|
49 |
+
gr.Slider(minimum=128, maximum=4096, value=2048, step=1, label="Max new tokens"),
|
50 |
+
gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature"),
|
51 |
+
gr.Slider(
|
52 |
+
minimum=0.1,
|
53 |
+
maximum=1.0,
|
54 |
+
value=0.9,
|
55 |
+
step=0.05,
|
56 |
+
label="Top-p (nucleus sampling)",
|
57 |
+
),
|
58 |
+
],
|
59 |
+
title="Med TinyLlama Chat",
|
60 |
+
description="Chat with the Med TinyLlama model for medical information.",
|
61 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
if __name__ == "__main__":
|
64 |
demo.launch()
|