1lch2 commited on
Commit
e2e4ca3
·
1 Parent(s): 11268fa

remove useless tile size slider

Browse files
Files changed (2) hide show
  1. app.py +26 -19
  2. requirements.txt +1 -1
app.py CHANGED
@@ -27,9 +27,25 @@ UltraSharp V2 — 图像超分辨率 Gradio 应用
27
  """
28
 
29
  import os
 
 
30
  import gradio as gr
31
  from model_loader import UltraSharpV2
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  # ---------------------------------------------------------------------------
34
  # ZeroGPU 兼容层
35
  # ---------------------------------------------------------------------------
@@ -55,11 +71,18 @@ def _gpu(fn):
55
  model = UltraSharpV2(device="cpu")
56
 
57
 
 
 
 
 
 
 
 
58
  # ---------------------------------------------------------------------------
59
  # 推理函数(生成器模式 — ZeroGPU 硬性要求)
60
  # ---------------------------------------------------------------------------
61
  @_gpu
62
- def on_upscale(image, tile_size, tile_overlap, target_scale):
63
  if image is None:
64
  yield None, "请先上传图片"
65
  return
@@ -67,7 +90,7 @@ def on_upscale(image, tile_size, tile_overlap, target_scale):
67
  model.to_cuda()
68
  try:
69
  result, elapsed = model.upscale(
70
- image, int(tile_size), int(tile_overlap), float(target_scale)
71
  )
72
  finally:
73
  model.to_cpu()
@@ -94,22 +117,6 @@ with gr.Blocks(title="UltraSharp V2") as demo:
94
  step=0.05,
95
  info="> 模型原生倍率时, 输出先 4x 推理再 Lanczos 缩放",
96
  )
97
- tile_size = gr.Slider(
98
- label="tile_size",
99
- minimum=128,
100
- maximum=1024,
101
- value=512,
102
- step=32,
103
- info="分块大小,越小越省显存",
104
- )
105
- tile_overlap = gr.Slider(
106
- label="tile_overlap",
107
- minimum=0,
108
- maximum=128,
109
- value=32,
110
- step=8,
111
- info="块间重叠像素",
112
- )
113
 
114
  with gr.Column(scale=1):
115
  run_btn = gr.Button("开始推理", variant="primary")
@@ -118,7 +125,7 @@ with gr.Blocks(title="UltraSharp V2") as demo:
118
 
119
  run_btn.click(
120
  fn=on_upscale,
121
- inputs=[input_img, tile_size, tile_overlap, target_scale],
122
  outputs=[output_img, status],
123
  )
124
 
 
27
  """
28
 
29
  import os
30
+ import signal
31
+ import asyncio
32
  import gradio as gr
33
  from model_loader import UltraSharpV2
34
 
35
+
36
+ def _cleanup(*_):
37
+ """Space 关闭时清理 asyncio 资源,避免 Python 3.12 的 fd=-1 报错。"""
38
+ try:
39
+ loop = asyncio.get_event_loop()
40
+ if not loop.is_closed():
41
+ loop.call_soon_threadsafe(loop.stop)
42
+ except Exception:
43
+ pass
44
+
45
+
46
+ signal.signal(signal.SIGTERM, _cleanup)
47
+ signal.signal(signal.SIGINT, _cleanup)
48
+
49
  # ---------------------------------------------------------------------------
50
  # ZeroGPU 兼容层
51
  # ---------------------------------------------------------------------------
 
71
  model = UltraSharpV2(device="cpu")
72
 
73
 
74
+ # ---------------------------------------------------------------------------
75
+ # 推理参数(RTX PRO 6000 Blackwell / 48GB — 无需省显存)
76
+ # ---------------------------------------------------------------------------
77
+ _TILE_SIZE = 1024
78
+ _TILE_OVERLAP = 48
79
+
80
+
81
  # ---------------------------------------------------------------------------
82
  # 推理函数(生成器模式 — ZeroGPU 硬性要求)
83
  # ---------------------------------------------------------------------------
84
  @_gpu
85
+ def on_upscale(image, target_scale):
86
  if image is None:
87
  yield None, "请先上传图片"
88
  return
 
90
  model.to_cuda()
91
  try:
92
  result, elapsed = model.upscale(
93
+ image, _TILE_SIZE, _TILE_OVERLAP, float(target_scale)
94
  )
95
  finally:
96
  model.to_cpu()
 
117
  step=0.05,
118
  info="> 模型原生倍率时, 输出先 4x 推理再 Lanczos 缩放",
119
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  with gr.Column(scale=1):
122
  run_btn = gr.Button("开始推理", variant="primary")
 
125
 
126
  run_btn.click(
127
  fn=on_upscale,
128
+ inputs=[input_img, target_scale],
129
  outputs=[output_img, status],
130
  )
131
 
requirements.txt CHANGED
@@ -1,6 +1,6 @@
1
  torch>=2.0
2
  spandrel>=0.3
3
- gradio>=4.0
4
  Pillow
5
  huggingface_hub
6
  spaces>=0.3
 
1
  torch>=2.0
2
  spandrel>=0.3
3
+ gradio>=5.0
4
  Pillow
5
  huggingface_hub
6
  spaces>=0.3