Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,38 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
-
|
10 |
def respond(
|
11 |
-
message,
|
12 |
history: list[tuple[str, str]],
|
13 |
-
system_message,
|
14 |
-
max_tokens,
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
-
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
for
|
21 |
-
if
|
22 |
-
messages.append({"role": "user", "content":
|
23 |
-
if
|
24 |
-
messages.append({"role": "assistant", "content":
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
@@ -35,13 +46,10 @@ def respond(
|
|
35 |
top_p=top_p,
|
36 |
):
|
37 |
token = message.choices[0].delta.content
|
38 |
-
|
39 |
response += token
|
40 |
yield response
|
41 |
|
42 |
-
|
43 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
44 |
-
"""
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
@@ -56,8 +64,9 @@ demo = gr.ChatInterface(
|
|
56 |
label="Top-p (nucleus sampling)",
|
57 |
),
|
58 |
],
|
|
|
|
|
59 |
)
|
60 |
|
61 |
-
|
62 |
if __name__ == "__main__":
|
63 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
# Initialize the InferenceClient
|
|
|
|
|
5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
6 |
|
|
|
7 |
def respond(
|
8 |
+
message: str,
|
9 |
history: list[tuple[str, str]],
|
10 |
+
system_message: str,
|
11 |
+
max_tokens: int,
|
12 |
+
temperature: float,
|
13 |
+
top_p: float,
|
14 |
+
) -> str:
|
15 |
+
"""
|
16 |
+
Generate a response based on the user's message and chat history.
|
17 |
+
|
18 |
+
Args:
|
19 |
+
message (str): The user's message.
|
20 |
+
history (list[tuple[str, str]]): The chat history.
|
21 |
+
system_message (str): The system message.
|
22 |
+
max_tokens (int): The maximum number of tokens in the response.
|
23 |
+
temperature (float): The temperature for sampling.
|
24 |
+
top_p (float): The top-p (nucleus) sampling value.
|
25 |
+
|
26 |
+
Returns:
|
27 |
+
str: The generated response.
|
28 |
+
"""
|
29 |
messages = [{"role": "system", "content": system_message}]
|
30 |
|
31 |
+
for user_msg, assistant_msg in history:
|
32 |
+
if user_msg:
|
33 |
+
messages.append({"role": "user", "content": user_msg})
|
34 |
+
if assistant_msg:
|
35 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
36 |
|
37 |
messages.append({"role": "user", "content": message})
|
38 |
|
|
|
46 |
top_p=top_p,
|
47 |
):
|
48 |
token = message.choices[0].delta.content
|
|
|
49 |
response += token
|
50 |
yield response
|
51 |
|
52 |
+
# Create the Gradio ChatInterface
|
|
|
|
|
53 |
demo = gr.ChatInterface(
|
54 |
respond,
|
55 |
additional_inputs=[
|
|
|
64 |
label="Top-p (nucleus sampling)",
|
65 |
),
|
66 |
],
|
67 |
+
theme="default", # Apply the default theme
|
68 |
+
css=".gradio-container {background-color: #E0F7FA;}" # Set a light blue background
|
69 |
)
|
70 |
|
|
|
71 |
if __name__ == "__main__":
|
72 |
demo.launch()
|