yjy7777 commited on
Commit
744a28c
·
1 Parent(s): e81e240

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # 创建一个文本生成管道
5
+ generator = pipeline('text-generation', model='gpt2')
6
+
7
+ def generate_text(prompt):
8
+ return generator(prompt, max_length=50, num_return_sequences=1)[0]['generated_text']
9
+
10
+ # 创建 Gradio 接口
11
+ iface = gr.Interface(
12
+ fn=generate_text,
13
+ inputs=gr.inputs.Textbox(lines=2, placeholder="输入一些文本..."),
14
+ outputs='text',
15
+ title="文本生成器",
16
+ description="使用 GPT-2 生成文本。输入一些文本并查看模型的生成结果。"
17
+ )
18
+
19
+ # 在本地运行应用
20
+ iface.launch()