syedaoon commited on
Commit
4e9fc8c
Β·
verified Β·
1 Parent(s): 9aea794

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +106 -39
app.py CHANGED
@@ -11,6 +11,10 @@ import time
11
 
12
  app = Flask(__name__)
13
 
 
 
 
 
14
  HTML_TEMPLATE = """
15
  <!DOCTYPE html>
16
  <html>
@@ -35,6 +39,7 @@ HTML_TEMPLATE = """
35
  .error { color: red; }
36
  .processing { color: orange; font-weight: bold; }
37
  .method-info { background: #e3f2fd; padding: 15px; margin: 10px 0; border-radius: 5px; }
 
38
  </style>
39
  <script>
40
  function selectMethod(method) {
@@ -59,7 +64,6 @@ HTML_TEMPLATE = """
59
  });
60
  }
61
 
62
- // Initialize with ZeroIG selected
63
  window.onload = function() {
64
  selectMethod('zeroig');
65
  }
@@ -68,7 +72,12 @@ HTML_TEMPLATE = """
68
  <body>
69
  <div class="container">
70
  <h1>🌟 Multi-Method Low-Light Enhancement</h1>
71
- <p>Choose your enhancement method and upload a low-light image!</p>
 
 
 
 
 
72
 
73
  <div class="method-selection">
74
  <h3>πŸ“š Select Enhancement Method:</h3>
@@ -83,18 +92,18 @@ HTML_TEMPLATE = """
83
  </button>
84
 
85
  <div class="method-info" data-method="zeroig">
86
- <strong>ZeroIG:</strong> Zero-shot illumination-guided joint denoising and adaptive enhancement.
87
- Fast, no training data required, prevents over-enhancement.
88
  </div>
89
 
90
  <div class="method-info" data-method="cfwd">
91
- <strong>CFWD:</strong> CLIP-Fourier Guided Wavelet Diffusion for low-light enhancement.
92
- State-of-the-art quality using diffusion models and CLIP guidance.
93
  </div>
94
 
95
  <div class="method-info" data-method="both">
96
- <strong>Comparison Mode:</strong> Process with both methods to see the differences.
97
- Takes longer but shows you the best of both approaches.
98
  </div>
99
  </div>
100
 
@@ -114,10 +123,6 @@ HTML_TEMPLATE = """
114
  <div class="status">{{ status }}</div>
115
  {% endif %}
116
 
117
- {% if processing %}
118
- <div class="processing">{{ processing }}</div>
119
- {% endif %}
120
-
121
  {% if error %}
122
  <div class="error">{{ error }}</div>
123
  {% endif %}
@@ -170,14 +175,14 @@ HTML_TEMPLATE = """
170
 
171
  <div style="margin: 15px 0;">
172
  <strong>🎯 ZeroIG (CVPR 2024):</strong>
173
- <p>Zero-shot illumination-guided joint denoising and adaptive enhancement. Fast and reliable.</p>
174
  <p>πŸ“„ <a href="https://openaccess.thecvf.com/content/CVPR2024/papers/Shi_ZERO-IG_Zero-Shot_Illumination-Guided_Joint_Denoising_and_Adaptive_Enhancement_for_Low-Light_CVPR_2024_paper.pdf">Paper</a> |
175
  πŸ’» <a href="https://github.com/Doyle59217/ZeroIG">Code</a></p>
176
  </div>
177
 
178
  <div style="margin: 15px 0;">
179
  <strong>🌊 CFWD (2024):</strong>
180
- <p>CLIP-Fourier Guided Wavelet Diffusion for state-of-the-art low-light enhancement.</p>
181
  <p>πŸ“„ <a href="https://arxiv.org/abs/2401.03788">Paper</a> |
182
  πŸ’» <a href="https://github.com/hejh8/CFWD">Code</a></p>
183
  </div>
@@ -187,6 +192,47 @@ HTML_TEMPLATE = """
187
  </html>
188
  """
189
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  class MultiMethodProcessor:
191
  def __init__(self):
192
  self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
@@ -195,7 +241,7 @@ class MultiMethodProcessor:
195
  print(f"Multi-method processor initialized on {self.device}")
196
 
197
  def load_zeroig(self):
198
- """Load ZeroIG model"""
199
  try:
200
  from model import Finetunemodel, Network
201
 
@@ -230,15 +276,33 @@ class MultiMethodProcessor:
230
  return None
231
 
232
  def load_cfwd(self):
233
- """Load CFWD model - placeholder for now"""
234
  try:
235
- # TODO: Implement CFWD model loading
236
- # This is where you'll add CFWD model loading code
237
- print("⚠️ CFWD model not yet implemented")
238
- return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
 
240
  except Exception as e:
241
- print(f"❌ CFWD not available: {e}")
242
  return None
243
 
244
  def enhance_with_zeroig(self, image):
@@ -282,26 +346,24 @@ class MultiMethodProcessor:
282
  return None, f"ZeroIG failed: {str(e)}"
283
 
284
  def enhance_with_cfwd(self, image):
285
- """Enhance image using CFWD - placeholder for now"""
286
  if self.cfwd_model is None:
287
- # TODO: Replace this with actual CFWD implementation
288
- # For now, return a simple enhancement as placeholder
289
- arr = np.array(image).astype(np.float32)
290
- enhanced = np.clip(arr * 2.2, 0, 255).astype(np.uint8)
291
- enhanced_image = Image.fromarray(enhanced)
292
- return enhanced_image, "CFWD placeholder (not yet implemented)"
 
 
 
293
 
294
  try:
295
- # TODO: Implement actual CFWD processing
 
296
  pass
297
  except Exception as e:
298
  return None, f"CFWD failed: {str(e)}"
299
-
300
- def simple_enhance(self, image):
301
- """Fallback simple enhancement"""
302
- arr = np.array(image).astype(np.float32)
303
- enhanced = np.clip(arr * 1.8, 0, 255).astype(np.uint8)
304
- return Image.fromarray(enhanced)
305
 
306
  # Initialize processor
307
  print("πŸš€ Loading multi-method processor...")
@@ -319,10 +381,12 @@ def index():
319
  results = None
320
  status = None
321
  error = None
322
- processing = None
323
  method_used = None
324
  processing_time = None
325
 
 
 
 
326
  if request.method == 'POST':
327
  try:
328
  file = request.files['image']
@@ -359,12 +423,15 @@ def index():
359
  zeroig_enhanced, zeroig_msg = processor.enhance_with_zeroig(image)
360
  cfwd_enhanced, cfwd_msg = processor.enhance_with_cfwd(image)
361
 
 
362
  if zeroig_enhanced:
363
  results['zeroig'] = image_to_base64(zeroig_enhanced)
 
364
  if cfwd_enhanced:
365
  results['cfwd'] = image_to_base64(cfwd_enhanced)
 
366
 
367
- status = f"βœ… Both methods completed"
368
 
369
  end_time = time.time()
370
  processing_time = round(end_time - start_time, 2)
@@ -375,13 +442,13 @@ def index():
375
  print(f"Error: {e}")
376
 
377
  return render_template_string(HTML_TEMPLATE,
 
378
  results=results,
379
  status=status,
380
  error=error,
381
- processing=processing,
382
  method_used=method_used,
383
  processing_time=processing_time)
384
 
385
  if __name__ == '__main__':
386
- print("πŸš€ Starting Multi-Method Enhancement App...")
387
  app.run(host='0.0.0.0', port=7860)
 
11
 
12
  app = Flask(__name__)
13
 
14
+ # Add paths for different methods
15
+ sys.path.append('.') # For ZeroIG (root folder)
16
+ sys.path.append('./CFWD') # For CFWD method
17
+
18
  HTML_TEMPLATE = """
19
  <!DOCTYPE html>
20
  <html>
 
39
  .error { color: red; }
40
  .processing { color: orange; font-weight: bold; }
41
  .method-info { background: #e3f2fd; padding: 15px; margin: 10px 0; border-radius: 5px; }
42
+ .folder-status { background: #fff3cd; padding: 10px; margin: 10px 0; border-radius: 5px; font-family: monospace; }
43
  </style>
44
  <script>
45
  function selectMethod(method) {
 
64
  });
65
  }
66
 
 
67
  window.onload = function() {
68
  selectMethod('zeroig');
69
  }
 
72
  <body>
73
  <div class="container">
74
  <h1>🌟 Multi-Method Low-Light Enhancement</h1>
75
+ <p>Professional low-light image enhancement with multiple state-of-the-art methods</p>
76
+
77
+ <div class="folder-status">
78
+ <strong>πŸ“ Method Status:</strong><br>
79
+ {{ method_status }}
80
+ </div>
81
 
82
  <div class="method-selection">
83
  <h3>πŸ“š Select Enhancement Method:</h3>
 
92
  </button>
93
 
94
  <div class="method-info" data-method="zeroig">
95
+ <strong>🎯 ZeroIG:</strong> Zero-shot illumination-guided joint denoising and adaptive enhancement.
96
+ Fast processing, no training data required, prevents over-enhancement artifacts.
97
  </div>
98
 
99
  <div class="method-info" data-method="cfwd">
100
+ <strong>🌊 CFWD:</strong> CLIP-Fourier Guided Wavelet Diffusion for low-light enhancement.
101
+ Uses diffusion models with CLIP guidance for state-of-the-art quality.
102
  </div>
103
 
104
  <div class="method-info" data-method="both">
105
+ <strong>πŸ”„ Comparison Mode:</strong> Process with both methods to see the differences.
106
+ Takes longer but shows you the best of both approaches side-by-side.
107
  </div>
108
  </div>
109
 
 
123
  <div class="status">{{ status }}</div>
124
  {% endif %}
125
 
 
 
 
 
126
  {% if error %}
127
  <div class="error">{{ error }}</div>
128
  {% endif %}
 
175
 
176
  <div style="margin: 15px 0;">
177
  <strong>🎯 ZeroIG (CVPR 2024):</strong>
178
+ <p>Zero-shot illumination-guided joint denoising and adaptive enhancement for low-light images.</p>
179
  <p>πŸ“„ <a href="https://openaccess.thecvf.com/content/CVPR2024/papers/Shi_ZERO-IG_Zero-Shot_Illumination-Guided_Joint_Denoising_and_Adaptive_Enhancement_for_Low-Light_CVPR_2024_paper.pdf">Paper</a> |
180
  πŸ’» <a href="https://github.com/Doyle59217/ZeroIG">Code</a></p>
181
  </div>
182
 
183
  <div style="margin: 15px 0;">
184
  <strong>🌊 CFWD (2024):</strong>
185
+ <p>Low-light Image Enhancement via CLIP-Fourier Guided Wavelet Diffusion.</p>
186
  <p>πŸ“„ <a href="https://arxiv.org/abs/2401.03788">Paper</a> |
187
  πŸ’» <a href="https://github.com/hejh8/CFWD">Code</a></p>
188
  </div>
 
192
  </html>
193
  """
194
 
195
+ def check_method_availability():
196
+ """Check which methods are available"""
197
+ status = []
198
+
199
+ # Check ZeroIG (root folder)
200
+ zeroig_files = ['model.py', 'loss.py', 'utils.py']
201
+ zeroig_ok = all(os.path.exists(f) for f in zeroig_files)
202
+
203
+ if zeroig_ok:
204
+ # Check for weights
205
+ weights_found = False
206
+ for weight_path in ["./weights/LOL.pt", "./weights/model.pt"]:
207
+ if os.path.exists(weight_path):
208
+ weights_found = True
209
+ break
210
+
211
+ if weights_found:
212
+ status.append("βœ… ZeroIG: Ready with trained weights")
213
+ else:
214
+ status.append("⚠️ ZeroIG: Available but no trained weights found")
215
+ else:
216
+ status.append("❌ ZeroIG: Missing required files")
217
+
218
+ # Check CFWD folder
219
+ cfwd_folder_exists = os.path.exists('./CFWD')
220
+ if cfwd_folder_exists:
221
+ cfwd_files = os.listdir('./CFWD')
222
+ status.append(f"πŸ“ CFWD folder: Found with {len(cfwd_files)} files")
223
+
224
+ # Check for common CFWD files
225
+ expected_cfwd_files = ['test.py', 'model.py', 'datasets.py']
226
+ found_files = [f for f in expected_cfwd_files if f in cfwd_files]
227
+ if found_files:
228
+ status.append(f"βœ… CFWD files found: {', '.join(found_files)}")
229
+ else:
230
+ status.append("⚠️ CFWD: Folder exists but expected files not found")
231
+ else:
232
+ status.append("❌ CFWD: Folder not found - please create ./CFWD/ and upload CFWD files")
233
+
234
+ return "<br>".join(status)
235
+
236
  class MultiMethodProcessor:
237
  def __init__(self):
238
  self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 
241
  print(f"Multi-method processor initialized on {self.device}")
242
 
243
  def load_zeroig(self):
244
+ """Load ZeroIG model from root folder"""
245
  try:
246
  from model import Finetunemodel, Network
247
 
 
276
  return None
277
 
278
  def load_cfwd(self):
279
+ """Load CFWD model from CFWD folder"""
280
  try:
281
+ # Check if CFWD folder exists
282
+ if not os.path.exists('./CFWD'):
283
+ print("❌ CFWD folder not found")
284
+ return None
285
+
286
+ # Add CFWD folder to path and try importing
287
+ sys.path.insert(0, './CFWD')
288
+
289
+ # Try to import CFWD modules (will depend on actual CFWD structure)
290
+ # This is a placeholder - you'll need to adapt based on actual CFWD files
291
+ try:
292
+ # Example imports - replace with actual CFWD imports
293
+ # from model import CFWDModel # Replace with actual CFWD model
294
+ # model = CFWDModel()
295
+ # model.load_weights('./CFWD/weights/cfwd_weights.pt')
296
+
297
+ print("⚠️ CFWD: Import structure not yet implemented")
298
+ return None
299
+
300
+ except ImportError as e:
301
+ print(f"❌ CFWD import failed: {e}")
302
+ return None
303
 
304
  except Exception as e:
305
+ print(f"❌ CFWD loading error: {e}")
306
  return None
307
 
308
  def enhance_with_zeroig(self, image):
 
346
  return None, f"ZeroIG failed: {str(e)}"
347
 
348
  def enhance_with_cfwd(self, image):
349
+ """Enhance image using CFWD"""
350
  if self.cfwd_model is None:
351
+ # Placeholder enhancement until CFWD is implemented
352
+ try:
353
+ # Simple placeholder - replace with actual CFWD processing
354
+ arr = np.array(image).astype(np.float32)
355
+ enhanced = np.clip(arr * 2.2, 0, 255).astype(np.uint8)
356
+ enhanced_image = Image.fromarray(enhanced)
357
+ return enhanced_image, "CFWD placeholder (upload CFWD files to ./CFWD/ folder for real processing)"
358
+ except Exception as e:
359
+ return None, f"CFWD placeholder failed: {str(e)}"
360
 
361
  try:
362
+ # TODO: Implement actual CFWD processing when files are uploaded
363
+ # This will depend on the actual CFWD model structure
364
  pass
365
  except Exception as e:
366
  return None, f"CFWD failed: {str(e)}"
 
 
 
 
 
 
367
 
368
  # Initialize processor
369
  print("πŸš€ Loading multi-method processor...")
 
381
  results = None
382
  status = None
383
  error = None
 
384
  method_used = None
385
  processing_time = None
386
 
387
+ # Check method availability
388
+ method_status = check_method_availability()
389
+
390
  if request.method == 'POST':
391
  try:
392
  file = request.files['image']
 
423
  zeroig_enhanced, zeroig_msg = processor.enhance_with_zeroig(image)
424
  cfwd_enhanced, cfwd_msg = processor.enhance_with_cfwd(image)
425
 
426
+ status_msgs = []
427
  if zeroig_enhanced:
428
  results['zeroig'] = image_to_base64(zeroig_enhanced)
429
+ status_msgs.append(f"ZeroIG: {zeroig_msg}")
430
  if cfwd_enhanced:
431
  results['cfwd'] = image_to_base64(cfwd_enhanced)
432
+ status_msgs.append(f"CFWD: {cfwd_msg}")
433
 
434
+ status = "βœ… " + " | ".join(status_msgs)
435
 
436
  end_time = time.time()
437
  processing_time = round(end_time - start_time, 2)
 
442
  print(f"Error: {e}")
443
 
444
  return render_template_string(HTML_TEMPLATE,
445
+ method_status=method_status,
446
  results=results,
447
  status=status,
448
  error=error,
 
449
  method_used=method_used,
450
  processing_time=processing_time)
451
 
452
  if __name__ == '__main__':
453
+ print("πŸš€ Starting Organized Multi-Method Enhancement App...")
454
  app.run(host='0.0.0.0', port=7860)