mzltest commited on
Commit
5c6d076
1 Parent(s): a7a0294

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -2,10 +2,10 @@ import gradio as gr
2
  import subprocess
3
 
4
 
5
- def generate_text(length, prefix, temperature):
6
  # 构建命令行参数
7
  my_prefix = "--prefix=" + prefix + ","
8
- args = ["python", "generate.py", f"--length={int(length)}", f"--nsamples=1", f"--prefix={prefix}", f"--temperature={temperature}"]
9
 
10
  # 执行命令并获取输出
11
  process = subprocess.Popen(args, stdout=subprocess.PIPE)
@@ -15,12 +15,16 @@ def generate_text(length, prefix, temperature):
15
  return output
16
 
17
  input_length = gr.Slider(label="生成文本长度", minimum=10, maximum=500, default=100,step=10)
18
- #input_nsamples = gr.Slider(label="生成文本数量", minimum=1, maximum=5, default=1,step=1)
19
  input_prefix = gr.Textbox(label="起始文本")
20
- input_temperature = gr.Slider(label="生成温度", minimum=0.1, maximum=2.0, default=0.7, step=0.1)
 
 
 
 
 
21
  output_text = gr.Textbox(label="生成的文本")
22
 
23
  title = "GPT2中文文本生成器"
24
  description = "cpu推理约1s/字,温度太低基本是无意义字符"
25
 
26
- gr.Interface(fn=generate_text, inputs=[input_length, input_prefix, input_temperature], outputs=output_text, title=title, description=description).launch()
 
2
  import subprocess
3
 
4
 
5
+ def generate_text(length, prefix, temperature,batchsize,topk,topp,rep):
6
  # 构建命令行参数
7
  my_prefix = "--prefix=" + prefix + ","
8
+ args = ["python", "generate.py", f"--length={int(length)}", f"--nsamples=1", f"--prefix={prefix}", f"--temperature={temperature}",f"--batch_size={int(batchsize)",f"--topk={int(topk)",f"--topp={topp}",f"--repetition_penalty={rep}"]
9
 
10
  # 执行命令并获取输出
11
  process = subprocess.Popen(args, stdout=subprocess.PIPE)
 
15
  return output
16
 
17
  input_length = gr.Slider(label="生成文本长度", minimum=10, maximum=500, default=100,step=10)
 
18
  input_prefix = gr.Textbox(label="起始文本")
19
+ input_temperature = gr.Slider(label="生成温度", minimum=0, maximum=2, default=1, step=0.01)
20
+ input_batchsize = gr.Slider(label="生成的batch size", minimum=1, maximum=8, default=4,step=1)
21
+ input_topk = gr.Slider(label="最高几选一", minimum=1, maximum=20, default=8, step=1)
22
+ input_topp = gr.Slider(label="最高积累概率", minimum=0, maximum=2, default=0,step=0.01)
23
+ input_repeat_penality = gr.Slider(label="重复罚值", minimum=0, maximum=2, default=1,step=0.01)
24
+
25
  output_text = gr.Textbox(label="生成的文本")
26
 
27
  title = "GPT2中文文本生成器"
28
  description = "cpu推理约1s/字,温度太低基本是无意义字符"
29
 
30
+ gr.Interface(fn=generate_text, inputs=[input_length, input_prefix, input_temperature,input_batchsize,input_topk,input_topp,input_repeat_penality], outputs=output_text, title=title, description=description).launch()