mzltest commited on
Commit
ff094ba
1 Parent(s): 9cf92f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -1,19 +1,17 @@
1
  import gradio as gr
2
- import os
3
- import sys
4
- from generate import main
5
 
6
  def generate_text(length, nsamples, prefix, temperature):
 
7
  my_prefix = "--prefix=" + prefix + ","
8
- sys.argv = [
9
- 'generate.py',
10
- f'--length={length}',
11
- f'--nsamples={nsamples}',
12
- my_prefix,
13
- f'--temperature={temperature}',
14
- '--model_path=model/model_epoch10'
15
- ]
16
- output = main()
17
  return output
18
 
19
  input_length = gr.Number(label="生成文本长度", min_value=1, max_value=10000, default=1000)
 
1
  import gradio as gr
2
+ import subprocess
3
+
 
4
 
5
  def generate_text(length, nsamples, prefix, temperature):
6
+ # 构建命令行参数
7
  my_prefix = "--prefix=" + prefix + ","
8
+ args = ["python", "generate.py", f"--length={length}", f"--nsamples={nsamples}", my_prefix, f"--temperature={temperature}", "--model_path=model/model_epoch10"]
9
+
10
+ # 执行命令并获取输出
11
+ process = subprocess.Popen(args, stdout=subprocess.PIPE)
12
+ output, error = process.communicate()
13
+ output = output.decode("utf-8")
14
+
 
 
15
  return output
16
 
17
  input_length = gr.Number(label="生成文本长度", min_value=1, max_value=10000, default=1000)