File size: 508 Bytes
e88630a
a03ce67
e88630a
626dc91
 
d782c6d
a03ce67
 
 
626dc91
56a9e4c
 
a03ce67
56a9e4c
a03ce67
 
 
626dc91
56a9e4c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import gradio as gr
from transformers import pipeline

# 使用 DistilGPT2(更小更快)
generator = pipeline("text-generation", model="distilgpt2")

def chat(message, history):
    result = generator(
        message,
        max_new_tokens=50,   # 輸出限制更小,加快生成
        do_sample=True,
        temperature=0.7,
        top_p=0.9
    )
    reply = result[0]["generated_text"]
    return reply

demo = gr.ChatInterface(fn=chat, title="AI 聊天機器人 (DistilGPT2)")

demo.launch()