Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ from transformers import pipeline
|
|
6 |
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
|
7 |
"""
|
8 |
#client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
9 |
-
|
10 |
modelpath = "distilgpt2"
|
11 |
|
12 |
pipe = pipeline(
|
@@ -44,29 +44,19 @@ def respond(
|
|
44 |
except Exception as e:
|
45 |
return f"Error: {str(e)}"
|
46 |
|
47 |
-
|
48 |
-
response = pipe(
|
49 |
-
messages,
|
50 |
-
max_new_tokens=max_tokens,
|
51 |
-
temperature=temperature,
|
52 |
-
top_p=top_p,
|
53 |
-
)[0]["generated_text"]
|
54 |
-
yield response
|
55 |
-
except Exception as e:
|
56 |
-
return f"Error: {str(e)}"
|
57 |
-
#response = ""
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
|
68 |
-
|
69 |
-
|
70 |
|
71 |
|
72 |
"""
|
|
|
6 |
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
|
7 |
"""
|
8 |
#client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
9 |
+
client = InferenceClient("distilbert/distilgpt2")
|
10 |
modelpath = "distilgpt2"
|
11 |
|
12 |
pipe = pipeline(
|
|
|
44 |
except Exception as e:
|
45 |
return f"Error: {str(e)}"
|
46 |
|
47 |
+
response = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
+
for message in client.chat_completion(
|
50 |
+
messages,
|
51 |
+
max_tokens=max_tokens,
|
52 |
+
stream=True,
|
53 |
+
temperature=temperature,
|
54 |
+
top_p=top_p,
|
55 |
+
):
|
56 |
+
token = message.choices[0].delta.content
|
57 |
|
58 |
+
response += token
|
59 |
+
yield response
|
60 |
|
61 |
|
62 |
"""
|