tumuyan2 commited on
Commit
e75ced3
·
1 Parent(s): e67ee13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -24,7 +24,7 @@ def print_log(task_id, filename, stage, status):
24
  print(f"任务{task_id}: {filename}, [{status}] {stage}")
25
 
26
  # 修改 start_process 函数,处理新增输入
27
- def start_process(input_file, input_url, input2, shape0_str, shape1_str, output_type=["TorchScript", "ONNX", "MNN", "ONNX"], input_suffix=".pth"):
28
  global task_counter
29
  task_counter += 1
30
  task_id = task_counter
@@ -216,7 +216,7 @@ def start_process(input_file, input_url, input2, shape0_str, shape1_str, output_
216
  yield [], log
217
 
218
 
219
- width_ratio = 4
220
  if os.path.exists(pt_path):
221
  print_log(task_id, input2, "转换为TorchScript模型", "跳过")
222
  log += "跳过转换为TorchScript模型\n"
@@ -240,7 +240,7 @@ def start_process(input_file, input_url, input2, shape0_str, shape1_str, output_
240
 
241
  # 转换为 ONNX 模型
242
  if "ONNX" in output_type or "NCNN" in output_type or "MNN" in output_type:
243
- if str(width_ratio) in input2:
244
  onnx_path = output_base + ".onnx"
245
  else:
246
  onnx_path = output_base + "-x" + str(width_ratio) + ".onnx"
@@ -393,7 +393,7 @@ with gr.Blocks() as demo:
393
  input2 = gr.Textbox(label="自定义文件名")
394
  output_type = gr.Dropdown(
395
  choices=["TorchScript", "ONNX", "Fixed", "MNN", "NCNN"],
396
- value=["TorchScript", "ONNX", "MNN", "ONNX"],
397
  multiselect=True,
398
  label="模型类型",
399
  info="1. 生成mnn和ncnn模型必须先生成onnx模型;2.如果选项中包含了Fixed,那么输出的onnx和mnn模型都使用固定shape的input。"
@@ -425,14 +425,14 @@ with gr.Blocks() as demo:
425
 
426
  # 添加范例
427
  examples = [
428
- [None, "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth", "", "1,3,128,128", "0,0,0,0"],
429
- [None, "https://github.com/Phhofm/models/releases/download/4xNomos8kSC/4xNomos8kSC.pth", "", "1,3,128,128", "0,0,0,0"],
430
- [None, "https://github.com/Phhofm/models/releases/download/1xDeJPG/1xDeJPG_SRFormer_light.pth", "", "1,3,128,128", "0,0,0,0"],
431
- [None, "https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/4x-WTP-ColorDS.pth", "", "1,3,128,128", "0,0,0,0"],
432
  ]
433
  gr.Examples(
434
  examples=examples,
435
- inputs=[input1_file, input1, input2, shape0_str, shape1_str],
436
  outputs=[output, log_textbox],
437
  fn=start_process
438
  )
 
24
  print(f"任务{task_id}: {filename}, [{status}] {stage}")
25
 
26
  # 修改 start_process 函数,处理新增输入
27
+ def start_process(input_file, input_url, input2, shape0_str, shape1_str, output_type, input_suffix=".pth"):
28
  global task_counter
29
  task_counter += 1
30
  task_id = task_counter
 
216
  yield [], log
217
 
218
 
219
+ width_ratio = 0
220
  if os.path.exists(pt_path):
221
  print_log(task_id, input2, "转换为TorchScript模型", "跳过")
222
  log += "跳过转换为TorchScript模型\n"
 
240
 
241
  # 转换为 ONNX 模型
242
  if "ONNX" in output_type or "NCNN" in output_type or "MNN" in output_type:
243
+ if str(width_ratio) in input2 or width_ratio >0:
244
  onnx_path = output_base + ".onnx"
245
  else:
246
  onnx_path = output_base + "-x" + str(width_ratio) + ".onnx"
 
393
  input2 = gr.Textbox(label="自定义文件名")
394
  output_type = gr.Dropdown(
395
  choices=["TorchScript", "ONNX", "Fixed", "MNN", "NCNN"],
396
+ value=["TorchScript", "ONNX", "MNN", "NCNN"],
397
  multiselect=True,
398
  label="模型类型",
399
  info="1. 生成mnn和ncnn模型必须先生成onnx模型;2.如果选项中包含了Fixed,那么输出的onnx和mnn模型都使用固定shape的input。"
 
425
 
426
  # 添加范例
427
  examples = [
428
+ [None, "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth", "", "1,3,128,128", "0,0,0,0", ["TorchScript", "ONNX", "MNN", "ONNX"]],
429
+ [None, "https://github.com/Phhofm/models/releases/download/4xNomos8kSC/4xNomos8kSC.pth", "", "1,3,128,128", "0,0,0,0", ["TorchScript", "ONNX", "MNN", "ONNX"]],
430
+ [None, "https://github.com/Phhofm/models/releases/download/1xDeJPG/1xDeJPG_SRFormer_light.pth", "", "1,3,128,128", "0,0,0,0", ["TorchScript", "ONNX", "MNN", "ONNX"]],
431
+ [None, "https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/4x-WTP-ColorDS.pth", "", "1,3,128,128", "0,0,0,0", ["ONNX", "MNN"]],
432
  ]
433
  gr.Examples(
434
  examples=examples,
435
+ inputs=[input1_file, input1, input2, shape0_str, shape1_str, output_type],
436
  outputs=[output, log_textbox],
437
  fn=start_process
438
  )