Update app.py
Browse files
app.py
CHANGED
@@ -3,16 +3,26 @@ from huggingface_hub import InferenceClient
|
|
3 |
|
4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
|
6 |
-
def respond(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
messages = [{"role": "system", "content": system_message}]
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
13 |
messages.append({"role": "user", "content": message})
|
14 |
|
15 |
response = ""
|
|
|
16 |
for message in client.chat_completion(
|
17 |
messages,
|
18 |
max_tokens=max_tokens,
|
@@ -21,60 +31,49 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
21 |
top_p=top_p,
|
22 |
):
|
23 |
token = message.choices[0].delta.content
|
|
|
24 |
response += token
|
25 |
yield response
|
26 |
|
27 |
# Custom CSS for improved visual appeal
|
28 |
custom_css = """
|
29 |
-
body {
|
30 |
-
background-color: #f0f4f8;
|
31 |
-
font-family: 'Arial', sans-serif;
|
32 |
-
}
|
33 |
.gradio-container {
|
34 |
max-width: 800px !important;
|
35 |
margin: auto;
|
36 |
padding: 20px;
|
37 |
-
border-radius:
|
38 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
39 |
-
background-color:
|
40 |
}
|
41 |
.chat-window {
|
42 |
-
border-radius:
|
43 |
border: 1px solid #e0e0e0;
|
|
|
44 |
}
|
45 |
-
.
|
46 |
-
|
|
|
|
|
47 |
border-radius: 8px;
|
48 |
-
margin: 5px 0;
|
49 |
-
}
|
50 |
-
.user-message {
|
51 |
-
background-color: #e3f2fd;
|
52 |
-
}
|
53 |
-
.bot-message {
|
54 |
-
background-color: #f1f8e9;
|
55 |
}
|
56 |
"""
|
57 |
|
58 |
-
# Create the ChatInterface with custom styling
|
59 |
demo = gr.ChatInterface(
|
60 |
respond,
|
61 |
additional_inputs=[
|
62 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System
|
63 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max
|
64 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
65 |
-
gr.Slider(
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
],
|
67 |
-
title="Enhanced AI Chatbot",
|
68 |
-
description="Engage in a conversation with an AI powered by the Zephyr-7b-beta model.",
|
69 |
-
theme="soft",
|
70 |
css=custom_css,
|
71 |
-
examples=[
|
72 |
-
["Tell me a short story about a robot learning to paint."],
|
73 |
-
["What are the main challenges in space exploration?"],
|
74 |
-
["Explain quantum computing to a 10-year-old."]
|
75 |
-
],
|
76 |
)
|
77 |
|
78 |
-
|
79 |
if __name__ == "__main__":
|
80 |
demo.launch()
|
|
|
3 |
|
4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
|
6 |
+
def respond(
|
7 |
+
message,
|
8 |
+
history: list[tuple[str, str]],
|
9 |
+
system_message,
|
10 |
+
max_tokens,
|
11 |
+
temperature,
|
12 |
+
top_p,
|
13 |
+
):
|
14 |
messages = [{"role": "system", "content": system_message}]
|
15 |
+
|
16 |
+
for val in history:
|
17 |
+
if val[0]:
|
18 |
+
messages.append({"role": "user", "content": val[0]})
|
19 |
+
if val[1]:
|
20 |
+
messages.append({"role": "assistant", "content": val[1]})
|
21 |
+
|
22 |
messages.append({"role": "user", "content": message})
|
23 |
|
24 |
response = ""
|
25 |
+
|
26 |
for message in client.chat_completion(
|
27 |
messages,
|
28 |
max_tokens=max_tokens,
|
|
|
31 |
top_p=top_p,
|
32 |
):
|
33 |
token = message.choices[0].delta.content
|
34 |
+
|
35 |
response += token
|
36 |
yield response
|
37 |
|
38 |
# Custom CSS for improved visual appeal
|
39 |
custom_css = """
|
|
|
|
|
|
|
|
|
40 |
.gradio-container {
|
41 |
max-width: 800px !important;
|
42 |
margin: auto;
|
43 |
padding: 20px;
|
44 |
+
border-radius: 10px;
|
45 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
46 |
+
background-color: #f8f9fa;
|
47 |
}
|
48 |
.chat-window {
|
49 |
+
border-radius: 8px;
|
50 |
border: 1px solid #e0e0e0;
|
51 |
+
background-color: white;
|
52 |
}
|
53 |
+
.additional-inputs {
|
54 |
+
margin-top: 20px;
|
55 |
+
padding: 15px;
|
56 |
+
background-color: #e9ecef;
|
57 |
border-radius: 8px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
}
|
59 |
"""
|
60 |
|
|
|
61 |
demo = gr.ChatInterface(
|
62 |
respond,
|
63 |
additional_inputs=[
|
64 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
65 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
66 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
67 |
+
gr.Slider(
|
68 |
+
minimum=0.1,
|
69 |
+
maximum=1.0,
|
70 |
+
value=0.95,
|
71 |
+
step=0.05,
|
72 |
+
label="Top-p (nucleus sampling)",
|
73 |
+
),
|
74 |
],
|
|
|
|
|
|
|
75 |
css=custom_css,
|
|
|
|
|
|
|
|
|
|
|
76 |
)
|
77 |
|
|
|
78 |
if __name__ == "__main__":
|
79 |
demo.launch()
|