remove additional inputs
Browse files
app.py
CHANGED
@@ -1,69 +1,47 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
|
|
4 |
with open("system_prompt.txt", "r") as f:
|
5 |
SYSTEM_PROMPT = f.read()
|
6 |
|
7 |
MODEL_NAME = "HuggingFaceH4/zephyr-7b-beta"
|
8 |
-
|
9 |
-
"""
|
10 |
-
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
|
11 |
-
"""
|
12 |
client = InferenceClient(MODEL_NAME)
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
if val[1]:
|
29 |
-
messages.append({"role": "assistant", "content": val[1]})
|
30 |
-
|
31 |
messages.append({"role": "user", "content": message})
|
32 |
-
|
33 |
response = ""
|
34 |
|
35 |
-
for
|
36 |
messages,
|
37 |
-
max_tokens=
|
38 |
stream=True,
|
39 |
-
temperature=
|
40 |
-
top_p=
|
41 |
):
|
42 |
-
token =
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
"""
|
49 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
50 |
-
"""
|
51 |
demo = gr.ChatInterface(
|
52 |
respond,
|
53 |
-
|
54 |
-
gr.Textbox(value=SYSTEM_PROMPT, label="System message"),
|
55 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
56 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
57 |
-
gr.Slider(
|
58 |
-
minimum=0.1,
|
59 |
-
maximum=1.0,
|
60 |
-
value=0.95,
|
61 |
-
step=0.05,
|
62 |
-
label="Top-p (nucleus sampling)",
|
63 |
-
),
|
64 |
-
],
|
65 |
)
|
66 |
|
67 |
-
|
68 |
if __name__ == "__main__":
|
69 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
# ---- System prompt and model ----
|
5 |
with open("system_prompt.txt", "r") as f:
|
6 |
SYSTEM_PROMPT = f.read()
|
7 |
|
8 |
MODEL_NAME = "HuggingFaceH4/zephyr-7b-beta"
|
|
|
|
|
|
|
|
|
9 |
client = InferenceClient(MODEL_NAME)
|
10 |
|
11 |
+
# ---- Fixed parameters ----
|
12 |
+
MAX_TOKENS = 512
|
13 |
+
TEMPERATURE = 0.7
|
14 |
+
TOP_P = 0.95
|
15 |
+
|
16 |
+
def respond(message, history):
|
17 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
18 |
+
|
19 |
+
for user_msg, bot_msg in history:
|
20 |
+
if user_msg:
|
21 |
+
messages.append({"role": "user", "content": user_msg})
|
22 |
+
if bot_msg:
|
23 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
24 |
+
|
|
|
|
|
|
|
25 |
messages.append({"role": "user", "content": message})
|
|
|
26 |
response = ""
|
27 |
|
28 |
+
for chunk in client.chat_completion(
|
29 |
messages,
|
30 |
+
max_tokens=MAX_TOKENS,
|
31 |
stream=True,
|
32 |
+
temperature=TEMPERATURE,
|
33 |
+
top_p=TOP_P,
|
34 |
):
|
35 |
+
token = chunk.choices[0].delta.content
|
36 |
+
if token:
|
37 |
+
response += token
|
38 |
+
yield response
|
39 |
|
40 |
+
# ---- Simple chat interface ----
|
|
|
|
|
|
|
41 |
demo = gr.ChatInterface(
|
42 |
respond,
|
43 |
+
title="BoundrAI",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
)
|
45 |
|
|
|
46 |
if __name__ == "__main__":
|
47 |
demo.launch()
|