Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,21 +14,19 @@ def get_client(model_name):
|
|
14 |
|
15 |
def respond(
|
16 |
message,
|
17 |
-
|
18 |
model_name,
|
19 |
-
system_message,
|
20 |
max_tokens,
|
21 |
temperature,
|
22 |
top_p,
|
|
|
23 |
):
|
24 |
client = get_client(model_name)
|
25 |
messages = [{"role": "system", "content": system_message}]
|
26 |
|
27 |
-
for
|
28 |
-
|
29 |
-
|
30 |
-
if val[1]:
|
31 |
-
messages.append({"role": "assistant", "content": val[1]})
|
32 |
|
33 |
messages.append({"role": "user", "content": message})
|
34 |
|
@@ -45,18 +43,33 @@ def respond(
|
|
45 |
response += token
|
46 |
yield response
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
gr.
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
if __name__ == "__main__":
|
62 |
demo.launch()
|
|
|
14 |
|
15 |
def respond(
|
16 |
message,
|
17 |
+
chat_history,
|
18 |
model_name,
|
|
|
19 |
max_tokens,
|
20 |
temperature,
|
21 |
top_p,
|
22 |
+
system_message,
|
23 |
):
|
24 |
client = get_client(model_name)
|
25 |
messages = [{"role": "system", "content": system_message}]
|
26 |
|
27 |
+
for human, assistant in chat_history:
|
28 |
+
messages.append({"role": "user", "content": human})
|
29 |
+
messages.append({"role": "assistant", "content": assistant})
|
|
|
|
|
30 |
|
31 |
messages.append({"role": "user", "content": message})
|
32 |
|
|
|
43 |
response += token
|
44 |
yield response
|
45 |
|
46 |
+
with gr.Blocks() as demo:
|
47 |
+
gr.Markdown("# Advanced AI Chatbot")
|
48 |
+
gr.Markdown("Chat with different language models and customize your experience!")
|
49 |
+
|
50 |
+
with gr.Row():
|
51 |
+
with gr.Column(scale=1):
|
52 |
+
model_name = gr.Radio(
|
53 |
+
choices=list(MODELS.keys()),
|
54 |
+
label="Language Model",
|
55 |
+
value="Zephyr 7B Beta"
|
56 |
+
)
|
57 |
+
max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max New Tokens")
|
58 |
+
temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature")
|
59 |
+
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
60 |
+
system_message = gr.Textbox(
|
61 |
+
value="You are a friendly and helpful AI assistant.",
|
62 |
+
label="System Message",
|
63 |
+
lines=3
|
64 |
+
)
|
65 |
+
|
66 |
+
with gr.Column(scale=2):
|
67 |
+
chatbot = gr.Chatbot()
|
68 |
+
msg = gr.Textbox(label="Your message")
|
69 |
+
clear = gr.Button("Clear")
|
70 |
+
|
71 |
+
msg.submit(respond, [msg, chatbot, model_name, max_tokens, temperature, top_p, system_message], chatbot)
|
72 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
73 |
|
74 |
if __name__ == "__main__":
|
75 |
demo.launch()
|