philipp-zettl
commited on
Commit
•
aa8720b
1
Parent(s):
70b7ce8
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,9 @@ 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 |
-
|
|
|
|
|
8 |
|
9 |
|
10 |
def respond(
|
@@ -26,18 +28,9 @@ def respond(
|
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
response = ""
|
29 |
-
|
30 |
-
|
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 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
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 |
+
from transformers import pipeline
|
8 |
+
|
9 |
+
pipe = pipeline("text-generation", model="HuggingFaceTB/SmolLM-135M-Instruct")
|
10 |
|
11 |
|
12 |
def respond(
|
|
|
28 |
messages.append({"role": "user", "content": message})
|
29 |
|
30 |
response = ""
|
31 |
+
for msg in pipe(messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p):
|
32 |
+
yield msg['generated_text']
|
33 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
"""
|
36 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|