Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# 使用
|
| 5 |
-
generator = pipeline("text-generation", model="
|
| 6 |
|
| 7 |
def chat(message, history):
|
| 8 |
result = generator(
|
| 9 |
message,
|
| 10 |
-
max_new_tokens=
|
| 11 |
do_sample=True,
|
| 12 |
temperature=0.7,
|
| 13 |
top_p=0.9
|
| 14 |
)
|
| 15 |
-
reply = reply[len(message):].strip()
|
| 16 |
reply = result[0]["generated_text"]
|
| 17 |
return reply
|
| 18 |
|
| 19 |
-
demo = gr.ChatInterface(fn=chat, title="AI 聊天機器人 (
|
| 20 |
|
| 21 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# 使用 DistilGPT2(更小更快)
|
| 5 |
+
generator = pipeline("text-generation", model="distilgpt2")
|
| 6 |
|
| 7 |
def chat(message, history):
|
| 8 |
result = generator(
|
| 9 |
message,
|
| 10 |
+
max_new_tokens=50, # 輸出限制更小,加快生成
|
| 11 |
do_sample=True,
|
| 12 |
temperature=0.7,
|
| 13 |
top_p=0.9
|
| 14 |
)
|
|
|
|
| 15 |
reply = result[0]["generated_text"]
|
| 16 |
return reply
|
| 17 |
|
| 18 |
+
demo = gr.ChatInterface(fn=chat, title="AI 聊天機器人 (DistilGPT2)")
|
| 19 |
|
| 20 |
demo.launch()
|