Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
|
4 |
-
from generate import main
|
5 |
|
6 |
def generate_text(length, nsamples, prefix, temperature):
|
|
|
7 |
my_prefix = "--prefix=" + prefix + ","
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
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)
|