Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,13 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
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,
|
@@ -26,27 +28,26 @@ def respond(
|
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
response = ""
|
29 |
-
|
30 |
-
for message in
|
31 |
-
|
32 |
max_tokens=max_tokens,
|
33 |
stream=True,
|
34 |
temperature=temperature,
|
35 |
top_p=top_p,
|
|
|
36 |
):
|
37 |
token = message.choices[0].delta.content
|
38 |
-
|
39 |
response += token
|
40 |
yield response
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
"""
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
demo = gr.ChatInterface(
|
47 |
respond,
|
48 |
additional_inputs=[
|
49 |
-
gr.Textbox(value="
|
50 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
gr.Slider(
|
@@ -54,11 +55,13 @@ demo = gr.ChatInterface(
|
|
54 |
maximum=1.0,
|
55 |
value=0.95,
|
56 |
step=0.05,
|
57 |
-
label="Top-
|
58 |
),
|
|
|
59 |
],
|
|
|
|
|
|
|
60 |
)
|
61 |
-
|
62 |
-
|
63 |
if __name__ == "__main__":
|
64 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from openai import OpenAI
|
3 |
+
import os
|
4 |
|
5 |
+
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
6 |
|
7 |
+
client = OpenAI(
|
8 |
+
base_url="https://api-inference.huggingface.co/v1/",
|
9 |
+
api_key=ACCESS_TOKEN,
|
10 |
+
)
|
11 |
|
12 |
def respond(
|
13 |
message,
|
|
|
28 |
messages.append({"role": "user", "content": message})
|
29 |
|
30 |
response = ""
|
31 |
+
|
32 |
+
for message in client.chat.completions.create(
|
33 |
+
model="NousResearch/Hermes-3-Llama-3.1-8B",
|
34 |
max_tokens=max_tokens,
|
35 |
stream=True,
|
36 |
temperature=temperature,
|
37 |
top_p=top_p,
|
38 |
+
messages=messages,
|
39 |
):
|
40 |
token = message.choices[0].delta.content
|
41 |
+
|
42 |
response += token
|
43 |
yield response
|
44 |
+
|
45 |
+
chatbot = gr.Chatbot(height=600)
|
46 |
|
|
|
|
|
|
|
|
|
47 |
demo = gr.ChatInterface(
|
48 |
respond,
|
49 |
additional_inputs=[
|
50 |
+
gr.Textbox(value="", label="System message"),
|
51 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
52 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
53 |
gr.Slider(
|
|
|
55 |
maximum=1.0,
|
56 |
value=0.95,
|
57 |
step=0.05,
|
58 |
+
label="Top-P",
|
59 |
),
|
60 |
+
|
61 |
],
|
62 |
+
fill_height=True,
|
63 |
+
chatbot=chatbot,
|
64 |
+
theme="Nymbo/Alyx_Theme",
|
65 |
)
|
|
|
|
|
66 |
if __name__ == "__main__":
|
67 |
+
demo.launch()
|