yangyufeng commited on
Commit
d07783b
·
1 Parent(s): 75642ae

update UI and fix transformer version

Browse files
Files changed (2) hide show
  1. app.py +120 -74
  2. requirements.txt +1 -1
app.py CHANGED
@@ -29,6 +29,12 @@ from PIL import Image
29
  MODEL_REPO_ID = os.environ.get("REALRESTORER_MODEL_REPO", "RealRestorer/RealRestorer")
30
  HF_TOKEN = os.environ.get("HF_TOKEN") or None
31
 
 
 
 
 
 
 
32
  TASK_PRESETS = {
33
  "Low-light Enhancement": "Please restore this low-quality image, recovering its normal brightness and clarity.",
34
  "Deblurring": "Please deblur the image and make it sharper.",
@@ -41,10 +47,11 @@ TASK_PRESETS = {
41
  "Reflection Removal": "Please remove the reflection from the image.",
42
  }
43
 
44
- DEFAULT_PRESET = "Reflection Removal"
45
  DEFAULT_STATUS = (
46
- "Model not loaded yet. Upload an image, pick a preset or edit the prompt, "
47
- "then click Run Inference."
 
48
  )
49
  DEFAULT_SLIDER = """
50
  <div style="text-align:center; padding:96px 24px; color:#7b8794; font-size:1.05rem;">
@@ -54,79 +61,114 @@ DEFAULT_SLIDER = """
54
 
55
  CUSTOM_CSS = """
56
  :root {
57
- --rr-ink: #102a43;
58
- --rr-muted: #5c6b7a;
59
- --rr-panel: rgba(255, 255, 255, 0.9);
60
- --rr-edge: rgba(16, 42, 67, 0.12);
61
- --rr-accent: #0f766e;
62
- --rr-accent-2: #f59e0b;
 
63
  }
64
 
65
  body {
 
66
  background:
67
- radial-gradient(circle at top left, rgba(15, 118, 110, 0.12), transparent 30%),
68
- radial-gradient(circle at top right, rgba(245, 158, 11, 0.12), transparent 28%),
69
- linear-gradient(180deg, #f7fafc 0%, #eef2f7 100%);
70
  }
71
 
72
  .gradio-container {
73
- max-width: 1380px !important;
74
  margin: 0 auto !important;
75
  }
76
 
 
 
 
 
 
 
 
 
77
  .rr-hero {
78
- padding: 20px 8px 10px;
79
  }
80
 
81
  .rr-hero h1 {
82
  margin: 0;
83
  text-align: center;
84
- font-size: 2.55rem;
85
- line-height: 1.05;
86
- letter-spacing: -0.04em;
87
- color: var(--rr-ink);
 
88
  }
89
 
90
  .rr-hero p {
91
- margin: 12px auto 0;
92
- max-width: 820px;
93
  text-align: center;
94
- color: var(--rr-muted);
95
  font-size: 1rem;
96
- line-height: 1.6;
97
- }
98
-
99
- .rr-shell {
100
- border: 1px solid var(--rr-edge);
101
- border-radius: 24px;
102
- background: rgba(255, 255, 255, 0.7);
103
- backdrop-filter: blur(16px);
104
- box-shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
105
- padding: 18px;
106
  }
107
 
108
  .rr-note {
109
- border-left: 4px solid var(--rr-accent);
110
  padding: 12px 14px;
111
  border-radius: 12px;
112
- background: rgba(15, 118, 110, 0.08);
113
- color: var(--rr-ink);
114
- margin-bottom: 8px;
115
  }
116
 
117
- .rr-foot {
118
- text-align: center;
119
- color: var(--rr-muted);
120
- font-size: 0.9rem;
121
- padding: 10px 0 2px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  }
123
 
124
  #run-btn {
125
- background: linear-gradient(135deg, var(--rr-accent) 0%, #0b8a7b 55%, var(--rr-accent-2) 100%) !important;
126
  color: white !important;
127
  border: none !important;
128
  font-weight: 700 !important;
129
  }
 
 
 
 
 
 
 
 
 
 
 
130
  """
131
 
132
  PIPELINE = None
@@ -190,7 +232,7 @@ def _load_pipeline():
190
 
191
  def _resolve_seed(seed: float | int | None) -> int:
192
  if seed is None:
193
- return random.randint(0, 2**31 - 1)
194
  seed_value = int(seed)
195
  if seed_value < 0:
196
  return random.randint(0, 2**31 - 1)
@@ -315,8 +357,8 @@ def build_demo() -> gr.Blocks:
315
  <h1>RealRestorer Image Restoration</h1>
316
  <p>
317
  Restore real-world degraded photos with the released RealRestorer model.
318
- Upload one image, choose a restoration preset, and compare the result with the
319
- interactive before/after slider.
320
  </p>
321
  </div>
322
  """
@@ -333,14 +375,14 @@ def build_demo() -> gr.Blocks:
333
  )
334
 
335
  with gr.Row():
336
- with gr.Column(scale=1):
337
  input_image = gr.Image(
338
  label="Input Image",
339
  type="pil",
340
  height=360,
341
  )
342
 
343
- with gr.Column(scale=1):
344
  preset_dropdown = gr.Dropdown(
345
  choices=list(TASK_PRESETS.keys()),
346
  value=DEFAULT_PRESET,
@@ -352,33 +394,37 @@ def build_demo() -> gr.Blocks:
352
  lines=4,
353
  )
354
 
355
- with gr.Accordion("Advanced Settings", open=False):
356
- steps_slider = gr.Slider(
357
- minimum=12,
358
- maximum=40,
359
- value=28,
360
- step=1,
361
- label="Inference Steps",
362
- )
363
- guidance_slider = gr.Slider(
364
- minimum=1.0,
365
- maximum=6.0,
366
- value=3.0,
367
- step=0.1,
368
- label="Guidance Scale",
369
- )
370
- size_level_slider = gr.Slider(
371
- minimum=512,
372
- maximum=1280,
373
- value=1024,
374
- step=64,
375
- label="Resize Target",
376
- )
377
- seed_box = gr.Number(
378
- label="Seed (-1 for random)",
379
- value=-1,
380
- precision=0,
381
- )
 
 
 
 
382
 
383
  run_button = gr.Button("Run Inference", variant="primary", elem_id="run-btn")
384
  status_box = gr.Textbox(
@@ -417,7 +463,7 @@ def build_demo() -> gr.Blocks:
417
  prompt_box,
418
  steps_slider,
419
  guidance_slider,
420
- size_level_slider,
421
  seed_box,
422
  ],
423
  outputs=[output_image, status_box, slider_html],
 
29
  MODEL_REPO_ID = os.environ.get("REALRESTORER_MODEL_REPO", "RealRestorer/RealRestorer")
30
  HF_TOKEN = os.environ.get("HF_TOKEN") or None
31
 
32
+ DEFAULT_STEPS = 28
33
+ DEFAULT_CFG = 3.0
34
+ DEFAULT_SIZE_LEVEL = 1024
35
+ DEFAULT_SEED = 42
36
+ SIZE_LEVEL_CHOICES = [512, 768, 1024, 1280]
37
+
38
  TASK_PRESETS = {
39
  "Low-light Enhancement": "Please restore this low-quality image, recovering its normal brightness and clarity.",
40
  "Deblurring": "Please deblur the image and make it sharper.",
 
47
  "Reflection Removal": "Please remove the reflection from the image.",
48
  }
49
 
50
+ DEFAULT_PRESET = "Low-light Enhancement"
51
  DEFAULT_STATUS = (
52
+ "Model not loaded yet. Upload an image, adjust the prompt or parameters, "
53
+ "then click Run Inference.\n"
54
+ f"Defaults: steps={DEFAULT_STEPS}, cfg={DEFAULT_CFG}, size={DEFAULT_SIZE_LEVEL}, seed={DEFAULT_SEED}"
55
  )
56
  DEFAULT_SLIDER = """
57
  <div style="text-align:center; padding:96px 24px; color:#7b8794; font-size:1.05rem;">
 
61
 
62
  CUSTOM_CSS = """
63
  :root {
64
+ --rr-primary: #667eea;
65
+ --rr-primary-hover: #5a67d8;
66
+ --rr-bg: #f7fafc;
67
+ --rr-border: #e2e8f0;
68
+ --rr-text-main: #2d3748;
69
+ --rr-text-muted: #718096;
70
+ --rr-radius: 10px;
71
  }
72
 
73
  body {
74
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
75
  background:
76
+ radial-gradient(circle at top left, rgba(102, 126, 234, 0.12), transparent 24%),
77
+ radial-gradient(circle at top right, rgba(240, 147, 251, 0.12), transparent 20%),
78
+ linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
79
  }
80
 
81
  .gradio-container {
82
+ max-width: 1240px !important;
83
  margin: 0 auto !important;
84
  }
85
 
86
+ .rr-shell {
87
+ background: white;
88
+ border: 1px solid var(--rr-border);
89
+ border-radius: 14px;
90
+ box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
91
+ padding: 28px !important;
92
+ }
93
+
94
  .rr-hero {
95
+ padding: 12px 0 22px;
96
  }
97
 
98
  .rr-hero h1 {
99
  margin: 0;
100
  text-align: center;
101
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
102
+ -webkit-background-clip: text;
103
+ -webkit-text-fill-color: transparent;
104
+ font-size: 2.5rem;
105
+ line-height: 1.1;
106
  }
107
 
108
  .rr-hero p {
109
+ margin: 14px auto 0;
110
+ max-width: 860px;
111
  text-align: center;
112
+ color: var(--rr-text-muted);
113
  font-size: 1rem;
114
+ line-height: 1.65;
 
 
 
 
 
 
 
 
 
115
  }
116
 
117
  .rr-note {
118
+ border-left: 4px solid var(--rr-primary);
119
  padding: 12px 14px;
120
  border-radius: 12px;
121
+ background: rgba(102, 126, 234, 0.08);
122
+ color: var(--rr-text-main);
123
+ margin-bottom: 14px;
124
  }
125
 
126
+ .rr-upload,
127
+ .rr-controls {
128
+ border: 1px solid var(--rr-border);
129
+ border-radius: var(--rr-radius);
130
+ padding: 16px;
131
+ background: #fff;
132
+ }
133
+
134
+ .rr-upload [data-testid="image"] {
135
+ border: 2px dashed #cbd5e0 !important;
136
+ border-radius: var(--rr-radius) !important;
137
+ background: #edf2f7 !important;
138
+ }
139
+
140
+ .rr-param-row {
141
+ gap: 12px;
142
+ }
143
+
144
+ .rr-param-card {
145
+ border: 1px solid var(--rr-border);
146
+ border-radius: var(--rr-radius);
147
+ padding: 10px 12px;
148
+ background: #f8fafc;
149
+ }
150
+
151
+ .rr-param-card .block {
152
+ margin: 0 !important;
153
  }
154
 
155
  #run-btn {
156
+ background: var(--rr-primary) !important;
157
  color: white !important;
158
  border: none !important;
159
  font-weight: 700 !important;
160
  }
161
+
162
+ #run-btn:hover {
163
+ background: var(--rr-primary-hover) !important;
164
+ }
165
+
166
+ .rr-foot {
167
+ text-align: center;
168
+ color: var(--rr-text-muted);
169
+ font-size: 0.9rem;
170
+ padding: 10px 0 2px;
171
+ }
172
  """
173
 
174
  PIPELINE = None
 
232
 
233
  def _resolve_seed(seed: float | int | None) -> int:
234
  if seed is None:
235
+ return DEFAULT_SEED
236
  seed_value = int(seed)
237
  if seed_value < 0:
238
  return random.randint(0, 2**31 - 1)
 
357
  <h1>RealRestorer Image Restoration</h1>
358
  <p>
359
  Restore real-world degraded photos with the released RealRestorer model.
360
+ Upload one image, choose a restoration preset, and tune the same core inference
361
+ controls you use in practice: seed, size, CFG, and steps.
362
  </p>
363
  </div>
364
  """
 
375
  )
376
 
377
  with gr.Row():
378
+ with gr.Column(scale=1, elem_classes=["rr-upload"]):
379
  input_image = gr.Image(
380
  label="Input Image",
381
  type="pil",
382
  height=360,
383
  )
384
 
385
+ with gr.Column(scale=1, elem_classes=["rr-controls"]):
386
  preset_dropdown = gr.Dropdown(
387
  choices=list(TASK_PRESETS.keys()),
388
  value=DEFAULT_PRESET,
 
394
  lines=4,
395
  )
396
 
397
+ with gr.Row(elem_classes=["rr-param-row"]):
398
+ with gr.Column(scale=1, elem_classes=["rr-param-card"]):
399
+ seed_box = gr.Number(
400
+ label="Seed (-1 for random)",
401
+ value=DEFAULT_SEED,
402
+ precision=0,
403
+ )
404
+ with gr.Column(scale=1, elem_classes=["rr-param-card"]):
405
+ size_level_dropdown = gr.Dropdown(
406
+ choices=SIZE_LEVEL_CHOICES,
407
+ value=DEFAULT_SIZE_LEVEL,
408
+ label="Resize Target",
409
+ )
410
+
411
+ with gr.Row(elem_classes=["rr-param-row"]):
412
+ with gr.Column(scale=1, elem_classes=["rr-param-card"]):
413
+ guidance_slider = gr.Slider(
414
+ minimum=1.0,
415
+ maximum=6.0,
416
+ value=DEFAULT_CFG,
417
+ step=0.1,
418
+ label="CFG / Guidance Scale",
419
+ )
420
+ with gr.Column(scale=1, elem_classes=["rr-param-card"]):
421
+ steps_slider = gr.Slider(
422
+ minimum=12,
423
+ maximum=40,
424
+ value=DEFAULT_STEPS,
425
+ step=1,
426
+ label="Inference Steps",
427
+ )
428
 
429
  run_button = gr.Button("Run Inference", variant="primary", elem_id="run-btn")
430
  status_box = gr.Textbox(
 
463
  prompt_box,
464
  steps_slider,
465
  guidance_slider,
466
+ size_level_dropdown,
467
  seed_box,
468
  ],
469
  outputs=[output_image, status_box, slider_html],
requirements.txt CHANGED
@@ -9,5 +9,5 @@ sentencepiece>=0.2.0
9
  timm>=1.0.0
10
  torch>=2.5.0
11
  torchvision>=0.20.0
12
- transformers>=4.57.0
13
  git+https://github.com/yfyang007/RealRestorer.git@705c7038c04fe66b0ed3cca64d192ecf88172619#subdirectory=diffusers
 
9
  timm>=1.0.0
10
  torch>=2.5.0
11
  torchvision>=0.20.0
12
+ transformers==4.57.3
13
  git+https://github.com/yfyang007/RealRestorer.git@705c7038c04fe66b0ed3cca64d192ecf88172619#subdirectory=diffusers