Spaces:
Configuration error
Configuration error
Create model_b.py
#3
by
liujiaxiang
- opened
- model_b.py +13 -0
model_b.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
|
| 3 |
+
# 中文 GPT2 模型(兼容 Hugging Face pipeline)
|
| 4 |
+
model_b = pipeline("text-generation", model="uer/gpt2-chinese-cluecorpussmall", tokenizer="uer/gpt2-chinese-cluecorpussmall")
|
| 5 |
+
|
| 6 |
+
def run_model_b(prompt: str) -> str:
|
| 7 |
+
output = model_b(prompt,
|
| 8 |
+
max_length=100,
|
| 9 |
+
do_sample=True,
|
| 10 |
+
temperature=0.8,
|
| 11 |
+
top_k=50,
|
| 12 |
+
top_p=0.95)
|
| 13 |
+
return output[0]["generated_text"]
|