tumuyan2 commited on
Commit
0dabb0f
·
1 Parent(s): da006e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -197,7 +197,8 @@ def download_file2folder(url: str, folder: str, filesize_max: int, filesize_min:
197
  os.remove(save_path)
198
  return None
199
 
200
- async def _process_model(model_input: Union[str, gr.File], tilesize: int, output_dir: str,task_id:int,fp16:bool,onnxsim:bool,opset:int,dynamic_axes:bool):
 
201
 
202
 
203
  log = ('初始化日志记录...\n')
@@ -244,7 +245,7 @@ async def _process_model(model_input: Union[str, gr.File], tilesize: int, output
244
  try:
245
  log += ( '正在将 ONNX 模型转换为 MNN 格式...\n')
246
  print_log(task_id, '正在将 ONNX 模型转换为 MNN 格式', '开始')
247
- convertmnn(onnx_path, mnn_path,fp16)
248
  yield onnx_path,log
249
  except Exception as e:
250
  log += ( f'转换 MNN 模型时出错: {str(e)}\n')
@@ -280,9 +281,10 @@ with gr.Blocks() as demo:
280
  input_type.change(show_input, inputs=input_type, outputs=[url_input, file_input])
281
  tilesize = gr.Number(label="Dummy input width/height, default 64", value=64, precision=0)
282
  opset = gr.Number(label="ONNX export opset version, suggest 9/11/13/16/17/18", value=13, precision=0)
283
- fp16 = gr.Checkbox(label="FP16", value=False)
284
  onnxsim = gr.Checkbox(label="ONNX export simplify model", value=False)
285
  dynamic_axes = gr.Checkbox(label="ONNX input apply dynamic axes", value=True)
 
286
  try_run = gr.Checkbox(label="MNNSR test", value=False)
287
  convert_btn = gr.Button("Run")
288
  with gr.Column():
@@ -298,9 +300,7 @@ with gr.Blocks() as demo:
298
  return gr.update(visible=False)
299
  try_run.change(show_try_run, inputs=try_run, outputs=img_output)
300
 
301
- async def process_model(input_type, url_input, file_input, tilesize, fp16, onnxsim, opset, dynamic_axes, try_run):
302
-
303
-
304
  global task_counter
305
  task_counter += 1
306
 
@@ -348,7 +348,8 @@ with gr.Blocks() as demo:
348
  onnx_path = None
349
  mnn_path = None
350
  # 调用重命名后的函数
351
- async for result in _process_model(model_input, tilesize if tilesize>0 else 64, output_dir, task_counter, fp16, onnxsim, opset, dynamic_axes):
 
352
 
353
  if isinstance(result, tuple) and len(result) == 3:
354
  onnx_path, mnn_path, process_log = result
@@ -372,17 +373,16 @@ with gr.Blocks() as demo:
372
 
373
  convert_btn.click(
374
  process_model,
375
- inputs=[input_type, url_input, file_input, tilesize, fp16, onnxsim, opset, dynamic_axes, try_run],
376
  outputs=[onnx_output, mnn_output, log_box, img_output],
377
  api_name="convert_nmm_model"
378
  )
379
 
380
- # 将示例移至底部并包裹在列组件中
381
  examples_column = gr.Column(visible=True)
382
  with examples_column:
383
  examples = [
384
  [model_type_opt[0], "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth"],
385
- [model_type_opt[0], "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth"],
386
  [model_type_opt[0], "https://github.com/Phhofm/models/releases/download/4xNomos8kSC/4xNomos8kSC.pth"],
387
  [model_type_opt[0], "https://github.com/Phhofm/models/releases/download/1xDeJPG/1xDeJPG_SRFormer_light.pth"],
388
  [model_type_opt[0], "https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/4x-WTP-ColorDS.pth"],
 
197
  os.remove(save_path)
198
  return None
199
 
200
+ async def _process_model(model_input: Union[str, gr.File], tilesize: int, output_dir: str,task_id:int,fp16:bool,onnxsim:bool,opset:int,dynamic_axes:bool,fp16mnn:bool):
201
+
202
 
203
 
204
  log = ('初始化日志记录...\n')
 
245
  try:
246
  log += ( '正在将 ONNX 模型转换为 MNN 格式...\n')
247
  print_log(task_id, '正在将 ONNX 模型转换为 MNN 格式', '开始')
248
+ convertmnn(onnx_path, mnn_path, fp16mnn)
249
  yield onnx_path,log
250
  except Exception as e:
251
  log += ( f'转换 MNN 模型时出错: {str(e)}\n')
 
281
  input_type.change(show_input, inputs=input_type, outputs=[url_input, file_input])
282
  tilesize = gr.Number(label="Dummy input width/height, default 64", value=64, precision=0)
283
  opset = gr.Number(label="ONNX export opset version, suggest 9/11/13/16/17/18", value=13, precision=0)
284
+ fp16 = gr.Checkbox(label="Use fp16 in ONNX export", value=False)
285
  onnxsim = gr.Checkbox(label="ONNX export simplify model", value=False)
286
  dynamic_axes = gr.Checkbox(label="ONNX input apply dynamic axes", value=True)
287
+ fp16mnn = gr.Checkbox(label="Use fp16 in MNN convert, only reduce filesize", value=True)
288
  try_run = gr.Checkbox(label="MNNSR test", value=False)
289
  convert_btn = gr.Button("Run")
290
  with gr.Column():
 
300
  return gr.update(visible=False)
301
  try_run.change(show_try_run, inputs=try_run, outputs=img_output)
302
 
303
+ async def process_model(input_type, url_input, file_input, tilesize, fp16, onnxsim, opset, dynamic_axes, fp16mnn,try_run):
 
 
304
  global task_counter
305
  task_counter += 1
306
 
 
348
  onnx_path = None
349
  mnn_path = None
350
  # 调用重命名后的函数
351
+ async for result in _process_model(model_input, tilesize if tilesize>0 else 64, output_dir, task_counter, fp16, onnxsim, opset, dynamic_axes, fp16mnn):
352
+
353
 
354
  if isinstance(result, tuple) and len(result) == 3:
355
  onnx_path, mnn_path, process_log = result
 
373
 
374
  convert_btn.click(
375
  process_model,
376
+ inputs=[input_type, url_input, file_input, tilesize, fp16, onnxsim, opset, dynamic_axes, fp16mnn, try_run],
377
  outputs=[onnx_output, mnn_output, log_box, img_output],
378
  api_name="convert_nmm_model"
379
  )
380
 
 
381
  examples_column = gr.Column(visible=True)
382
  with examples_column:
383
  examples = [
384
  [model_type_opt[0], "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth"],
385
+ [model_type_opt[0], "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth"],
386
  [model_type_opt[0], "https://github.com/Phhofm/models/releases/download/4xNomos8kSC/4xNomos8kSC.pth"],
387
  [model_type_opt[0], "https://github.com/Phhofm/models/releases/download/1xDeJPG/1xDeJPG_SRFormer_light.pth"],
388
  [model_type_opt[0], "https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/4x-WTP-ColorDS.pth"],