Spaces:
Running
Running
ayan4m1
commited on
Commit
·
49ecfa7
1
Parent(s):
8892a9c
use text_generation instead of chat_completion, re-add top-k
Browse files
app.py
CHANGED
@@ -4,34 +4,26 @@ from huggingface_hub import InferenceClient
|
|
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(
|
8 |
|
9 |
|
10 |
def respond(
|
11 |
message,
|
12 |
-
|
13 |
max_tokens: int,
|
14 |
temperature: float,
|
15 |
-
top_p: float
|
|
|
16 |
):
|
17 |
-
messages = []
|
18 |
-
|
19 |
-
for val in history:
|
20 |
-
if val[0]:
|
21 |
-
messages.append({"role": "user", "content": val[0]})
|
22 |
-
if val[1]:
|
23 |
-
messages.append({"role": "assistant", "content": val[1]})
|
24 |
-
|
25 |
-
messages.append({"role": "user", "content": message})
|
26 |
-
|
27 |
response = ""
|
28 |
|
29 |
-
for message in client.
|
30 |
-
|
31 |
max_tokens=max_tokens,
|
32 |
stream=True,
|
33 |
temperature=temperature,
|
34 |
-
top_p=top_p
|
|
|
35 |
):
|
36 |
token = message.choices[0].delta.content
|
37 |
|
@@ -54,6 +46,13 @@ demo = gr.ChatInterface(
|
|
54 |
step=0.05,
|
55 |
label="Top-p",
|
56 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
],
|
58 |
)
|
59 |
|
|
|
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(model="pszemraj/distilgpt2-magicprompt-SD")
|
8 |
|
9 |
|
10 |
def respond(
|
11 |
message,
|
12 |
+
_: list[tuple[str, str]],
|
13 |
max_tokens: int,
|
14 |
temperature: float,
|
15 |
+
top_p: float,
|
16 |
+
top_k: int
|
17 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
response = ""
|
19 |
|
20 |
+
for message in client.text_generation(
|
21 |
+
message,
|
22 |
max_tokens=max_tokens,
|
23 |
stream=True,
|
24 |
temperature=temperature,
|
25 |
+
top_p=top_p,
|
26 |
+
top_k=top_k
|
27 |
):
|
28 |
token = message.choices[0].delta.content
|
29 |
|
|
|
46 |
step=0.05,
|
47 |
label="Top-p",
|
48 |
),
|
49 |
+
gr.Slider(
|
50 |
+
minimum=10,
|
51 |
+
maximum=100,
|
52 |
+
value=30,
|
53 |
+
step=5,
|
54 |
+
label="Top-k",
|
55 |
+
),
|
56 |
],
|
57 |
)
|
58 |
|