prateeksharmacoder commited on
Commit
1984142
Β·
1 Parent(s): 4e2a788

UI redesign: match SentiEnhance mockup - light theme, teal accents, satellite navbar, improved layout

Browse files
Files changed (1) hide show
  1. app.py +732 -244
app.py CHANGED
@@ -63,89 +63,510 @@ def infer_esrgan(image):
63
  # ============================================================
64
 
65
  CSS = """
66
- /* Google Font */
67
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
 
68
 
69
  body, .gradio-container {
70
  font-family: 'Inter', sans-serif !important;
71
- background-color: #f8fafc !important;
 
 
72
  }
73
 
74
- /* Hide default Gradio padding/footers */
75
  footer { display: none !important; }
76
  .gradio-container { max-width: 100% !important; padding: 0 !important; margin: 0 !important; }
 
77
 
78
- /* Top Navbar */
79
  .top-nav {
80
- background: linear-gradient(135deg, #03182b 0%, #07355c 100%);
81
- padding: 20px 40px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  display: flex;
 
 
 
 
 
 
 
 
 
 
 
 
83
  justify-content: space-between;
 
 
 
 
 
 
84
  align-items: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  color: white;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  }
87
- .nav-left { display: flex; align-items: center; gap: 16px; }
88
- .nav-logo-icon { width: 36px; height: 36px; fill: #38bdf8; }
89
- .nav-title { display: flex; flex-direction: column; }
90
- .nav-logo-text { font-size: 1.6rem; font-weight: 700; color: #38bdf8; margin: 0; line-height: 1.1; }
91
- .nav-logo-text span { color: white; }
92
- .nav-subtitle { font-size: 0.8rem; color: #cbd5e1; margin: 0; }
93
- .nav-links { display: flex; gap: 30px; font-size: 0.95rem; align-items: center; }
94
- .nav-links a { color: #cbd5e1; text-decoration: none; font-weight: 500; transition: color 0.2s; }
95
- .nav-links a:hover { color: white; }
96
- .nav-links a.active { color: white; border-bottom: 2px solid white; padding-bottom: 4px; }
97
- .nav-btn { background: #34d399; color: #064e3b !important; padding: 10px 20px; border-radius: 6px; font-weight: 600; text-decoration: none; transition: background 0.2s; }
98
- .nav-btn:hover { background: #10b981; }
99
-
100
- /* Sidebar */
101
- .sidebar-container { background: #f8fafc; padding: 30px 20px; height: 100%; border-right: 1px solid #e2e8f0; display: flex; flex-direction: column; justify-content: space-between; }
102
- .sidebar-links { display: flex; flex-direction: column; gap: 8px; }
103
- .sidebar-link { display: flex; align-items: center; padding: 14px 20px; border-radius: 10px; color: #475569; text-decoration: none; font-weight: 500; font-size: 0.95rem; gap: 16px; transition: background 0.2s; cursor: pointer; }
104
- .sidebar-link:hover { background: #f1f5f9; }
105
- .sidebar-link.active { background: #d1fae5; color: #065f46; font-weight: 600; }
106
- .sidebar-link svg { width: 20px; height: 20px; }
107
- .sidebar-banner { background: #e0f2fe; padding: 24px 20px; border-radius: 16px; text-align: center; color: #0369a1; display: flex; flex-direction: column; align-items: center; gap: 12px; }
108
- .sidebar-banner svg { width: 40px; height: 40px; color: #0284c7; }
109
- .sidebar-banner div { font-weight: 600; font-size: 0.95rem; line-height: 1.4; }
110
-
111
- /* Main Content Area */
112
- .main-wrapper { padding: 30px 40px; }
113
- .page-title { font-size: 2.2rem; font-weight: 700; color: #0f172a; margin: 0 0 8px; letter-spacing: -0.5px; }
114
- .page-title span { color: #0369a1; }
115
- .page-subtitle { color: #64748b; font-size: 1.05rem; margin: 0 0 30px; }
116
-
117
- /* Upload box */
118
- .upload-card { background: white !important; border-radius: 16px !important; padding: 0 !important; border: 1px dashed #cbd5e1 !important; box-shadow: 0 4px 20px rgba(0,0,0,0.03) !important; overflow: hidden; }
119
-
120
- /* Model Select & Enhance Button */
121
- .model-card { background: white; border-radius: 12px; padding: 20px; border: 1px solid #e2e8f0; box-shadow: 0 4px 6px rgba(0,0,0,0.02); margin-bottom: 20px; }
122
- .model-card-title { font-size: 1rem; font-weight: 600; color: #1e293b; margin-bottom: 12px; }
123
- .model-info-box { background: #f0f9ff; color: #0369a1; padding: 14px; border-radius: 8px; font-size: 0.85rem; margin-top: 12px; display: flex; gap: 12px; align-items: flex-start; line-height: 1.5; }
124
- #enhance-btn { background: #0f9d58 !important; color: white !important; font-weight: 600 !important; font-size: 1.1rem !important; padding: 16px !important; border-radius: 8px !important; border: none !important; width: 100%; transition: all 0.2s; }
125
- #enhance-btn:hover { background: #0b8043 !important; transform: translateY(-1px); }
126
-
127
- /* Features List */
128
- .features-card { background: #f8fafc; border-radius: 12px; padding: 24px; border: 1px solid #e2e8f0; height: 100%; display: flex; flex-direction: column; justify-content: center; }
129
- .features-title { font-size: 1.1rem; font-weight: 600; color: #0f172a; margin-bottom: 20px; }
130
- .feature-item { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; color: #334155; font-size: 0.95rem; font-weight: 500; }
131
- .feature-icon { width: 24px; height: 24px; color: #0f9d58; flex-shrink: 0; }
132
-
133
- /* Results */
134
- .results-header { font-size: 1.4rem; font-weight: 700; color: #0f172a; margin: 40px 0 20px; }
135
- .image-card { border-radius: 12px !important; overflow: hidden; border: 1px solid #e2e8f0; background: white; padding: 0 !important; box-shadow: 0 4px 12px rgba(0,0,0,0.04); }
136
-
137
- /* Buttons */
138
- .download-col { display: flex; flex-direction: column; gap: 12px; padding-top: 36px; }
139
- .btn-primary { background: #0f9d58 !important; color: white !important; padding: 12px 16px !important; border-radius: 8px !important; font-weight: 600 !important; text-align: center; border: none !important; }
140
- .btn-outline { background: white !important; color: #334155 !important; border: 1px solid #cbd5e1 !important; padding: 12px 16px !important; border-radius: 8px !important; font-weight: 500 !important; text-align: center; box-shadow: 0 1px 2px rgba(0,0,0,0.02) !important; }
141
-
142
- /* Footer */
143
- .footer-strip { background: #03182b; color: white; padding: 24px 40px; display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; margin-top: 40px; }
144
- .footer-left { display: flex; gap: 10px; align-items: center; color: #cbd5e1; }
145
- .footer-left strong { color: white; }
146
- .footer-links { display: flex; gap: 24px; color: #94a3b8; align-items: center; }
147
- .footer-links a { color: #94a3b8; text-decoration: none; transition: color 0.2s; }
148
  .footer-links a:hover { color: white; }
 
 
 
149
  """
150
 
151
  # ============================================================
@@ -154,106 +575,96 @@ footer { display: none !important; }
154
 
155
  def run_super_resolution(image_path, model_choice, progress=gr.Progress()):
156
  if image_path is None:
157
- raise gr.Error("⚠️ Please upload a satellite image before running.")
158
 
159
  model_map = {"HAT-SAT (Recommended)": "hatsat", "ESRGAN (Baseline)": "esrgan"}
160
  selected_model = model_map.get(model_choice)
161
  if selected_model is None:
162
- raise gr.Error("⚠️ Please select a valid model.")
163
 
164
  if not isinstance(image_path, list):
165
  image_path = [image_path]
166
-
167
  is_tiff = False
168
-
 
169
  if len(image_path) == 3:
170
  paths = [str(p) for p in image_path]
171
  if not all(p.lower().endswith(('.tif', '.tiff')) for p in paths):
172
- raise gr.Error("⚠️ When uploading multiple files, they must all be TIFF files.")
173
-
174
  red_path = next((p for p in paths if "B04" in p.upper()), None)
175
  green_path = next((p for p in paths if "B03" in p.upper()), None)
176
  blue_path = next((p for p in paths if "B02" in p.upper()), None)
177
-
178
  if not (red_path and green_path and blue_path):
179
  paths = sorted(paths)
180
  blue_path, green_path, red_path = paths[0], paths[1], paths[2]
181
-
182
  try:
183
  with rasterio.open(red_path) as src_r, rasterio.open(green_path) as src_g, rasterio.open(blue_path) as src_b:
184
  profile = src_r.profile.copy()
185
  profile.update(count=3)
186
-
187
  if not (src_r.width == src_g.width == src_b.width and src_r.height == src_g.height == src_b.height):
188
- raise gr.Error("⚠️ The uploaded bands have mismatched dimensions.")
189
-
190
  r_data = src_r.read(1)
191
  g_data = src_g.read(1)
192
  b_data = src_b.read(1)
193
-
194
  data = np.stack([r_data, g_data, b_data], axis=-1)
195
  input_w, input_h = src_r.width, src_r.height
196
  is_tiff = True
197
-
 
198
  except Exception as e:
199
- raise gr.Error(f"⚠️ Error reading 3-band TIFFs: {str(e)}")
200
-
201
  if data.dtype != np.uint8:
202
  data = normalize_rgb(data)
203
-
204
  original_image = Image.fromarray(data, mode="RGB")
205
-
206
  elif len(image_path) == 1:
207
  file_path = str(image_path[0])
208
  is_tiff = file_path.lower().endswith(('.tif', '.tiff'))
209
-
210
  if is_tiff:
211
  try:
212
  with rasterio.open(file_path) as src:
213
  profile = src.profile.copy()
214
  count = src.count
215
  if count not in [1, 3, 4]:
216
- raise gr.Error(f"⚠️ Unsupported band count: {count}. Expected 1, 3, or 4 bands.")
217
-
218
- if count == 3:
219
- data = src.read([1, 2, 3])
220
- data = np.transpose(data, (1, 2, 0))
221
- elif count == 4:
222
  data = src.read([1, 2, 3])
223
  data = np.transpose(data, (1, 2, 0))
224
  else:
225
  data = src.read(1)
226
  data = np.stack([data, data, data], axis=-1)
227
-
228
  input_w, input_h = src.width, src.height
 
 
229
  except rasterio.errors.RasterioIOError:
230
- raise gr.Error("⚠️ Corrupted TIFF or unsupported format.")
231
  except Exception as e:
232
- raise gr.Error(f"⚠️ Error reading TIFF: {str(e)}")
233
-
234
- if data.dtype == np.uint8:
235
- pass
236
- else:
237
  data = normalize_rgb(data)
238
-
239
  original_image = Image.fromarray(data, mode="RGB")
240
  else:
241
  try:
242
  original_image = Image.open(file_path).convert("RGB")
243
  input_w, input_h = original_image.size
244
  except Exception:
245
- raise gr.Error("⚠️ Could not read image.")
246
  else:
247
- raise gr.Error("⚠️ Please upload either 1 file (multiband image) or 3 files (B04, B03, B02 GeoTIFFs).")
248
 
249
  if input_w < 16 or input_h < 16:
250
- raise gr.Error(f"⚠️ Image too small ({input_w}x{input_h}). Please upload an image at least 16x16 pixels.")
251
  if input_w > 1024 or input_h > 1024:
252
- raise gr.Error(f"⚠️ Image too large ({input_w}x{input_h}). Please use images up to 1024x1024 pixels.")
253
 
254
- start_time = time.time()
255
  try:
256
- progress(0.5, desc=f"Running {selected_model} 4x super-resolution (ZeroGPU) πŸš€")
257
  if selected_model == "hatsat":
258
  result = infer_hatsat(original_image)
259
  else:
@@ -261,16 +672,14 @@ def run_super_resolution(image_path, model_choice, progress=gr.Progress()):
261
  except Exception as e:
262
  raise gr.Error(f"{selected_model} inference failed: {e}")
263
 
264
- progress(0.9, desc="Finalising output πŸš€")
265
 
266
- # Generate PNG download
267
  tmp_png = tempfile.NamedTemporaryFile(suffix=f"_sr_{selected_model}_4x.png", delete=False)
268
  result.save(tmp_png.name, format="PNG")
269
  tmp_png.close()
270
  out_png = tmp_png.name
271
 
272
- # Generate TIFF download if input was TIFF
273
- if is_tiff:
274
  tmp_tiff = tempfile.NamedTemporaryFile(suffix=f"_sr_{selected_model}_4x_georef.tif", delete=False)
275
  tmp_tiff.close()
276
  save_sr_geotiff(result, profile, tmp_tiff.name, scale=4)
@@ -278,103 +687,134 @@ def run_super_resolution(image_path, model_choice, progress=gr.Progress()):
278
  else:
279
  out_tiff = None
280
 
281
- progress(1.0, desc="Done.")
282
-
283
- # Return: original preview, enhanced preview, png download, tiff download
284
  return original_image, result, gr.update(value=out_png, interactive=True), gr.update(value=out_tiff, interactive=True)
285
 
286
 
287
  # ============================================================
288
- # HTML COMPONENTS
289
  # ============================================================
290
 
291
  TOP_NAV = """
292
  <div class="top-nav">
293
- <div class="nav-left">
294
- <svg class="nav-logo-icon" viewBox="0 0 24 24"><path d="M12 2L2 22h20L12 2zm0 4.2l6.8 13.8H5.2L12 6.2z"/><path d="M12 10.5l-2.5 5h5z"/></svg>
295
- <div class="nav-title">
296
- <h1 class="nav-logo-text">Senti<span>Enhance</span></h1>
297
- <p class="nav-subtitle">AI-Powered Super-Resolution for Sentinel-2 Imagery</p>
298
- </div>
 
 
 
 
299
  </div>
300
- <div class="nav-links">
301
- <a href="#" class="active">Home</a>
302
- <a href="#">About</a>
303
- <a href="#">How It Works</a>
304
- <a href="#">Use Cases</a>
305
- <a href="#">Contact</a>
306
- <a href="#" class="nav-btn">Get Started</a>
307
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  </div>
309
  """
310
 
311
- SIDEBAR = """
312
- <div class="sidebar-container">
313
- <div class="sidebar-links">
314
- <a href="#" class="sidebar-link active">
315
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"></path></svg>
316
- Super-Resolution
317
- </a>
318
- <a href="#" class="sidebar-link">
319
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"></path></svg>
320
- Compare
321
- </a>
322
- <a href="#" class="sidebar-link">
323
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"></path></svg>
324
- Image Gallery
325
- </a>
326
- <a href="#" class="sidebar-link">
327
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
328
- Documentation
329
- </a>
330
- <a href="#" class="sidebar-link">
331
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
332
- About Project
333
- </a>
334
- </div>
335
- <div class="sidebar-banner">
336
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
337
- <div>Satellite data<br>for a sustainable<br>future</div>
338
- </div>
 
 
 
 
 
 
 
 
 
339
  </div>
340
  """
341
 
342
- WHY_USE_US = """
343
- <div class="features-title">Why Use Our Platform?</div>
344
- <div class="feature-item">
345
- <svg class="feature-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path></svg>
 
346
  AI-powered super-resolution
347
- </div>
348
- <div class="feature-item">
349
- <svg class="feature-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4"></path></svg>
350
  Supports Sentinel-2 imagery
351
- </div>
352
- <div class="feature-item">
353
- <svg class="feature-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path></svg>
354
  Preserves geospatial metadata
355
- </div>
356
- <div class="feature-item">
357
- <svg class="feature-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path></svg>
358
  Easy to use web interface
359
- </div>
360
- <div class="feature-item">
361
- <svg class="feature-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
362
- Free for research & education
 
363
  </div>
364
  """
365
 
366
- FOOTER = """
367
- <div class="footer-strip">
368
- <div class="footer-left">
369
- <strong>SentiEnhance</strong> | AI for a Sustainable Planet
370
- </div>
371
- <div class="footer-links">
372
- <a href="#">Privacy Policy</a> |
373
- <a href="#">Terms of Use</a> |
374
- <a href="#">Contact</a>
375
- <a href="#"><svg width="18" height="18" fill="currentColor" viewBox="0 0 24 24"><path d="M19 0h-14c-2.761 0-5 2.239-5 5v14c0 2.761 2.239 5 5 5h14c2.762 0 5-2.239 5-5v-14c0-2.761-2.238-5-5-5zm-11 19h-3v-11h3v11zm-1.5-12.268c-.966 0-1.75-.79-1.75-1.764s.784-1.764 1.75-1.764 1.75.79 1.75 1.764-.783 1.764-1.75 1.764zm13.5 12.268h-3v-5.604c0-3.368-4-3.113-4 0v5.604h-3v-11h3v1.765c1.396-2.586 7-2.777 7 2.476v6.759z"/></svg></a>
376
- <a href="#"><svg width="18" height="18" fill="currentColor" viewBox="0 0 24 24"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg></a>
377
- </div>
 
 
 
 
 
 
378
  </div>
379
  """
380
 
@@ -382,73 +822,122 @@ FOOTER = """
382
  # APP LAYOUT
383
  # ============================================================
384
 
385
- with gr.Blocks(theme=gr.themes.Base(), css=CSS) as demo:
386
-
387
  gr.HTML(TOP_NAV)
388
-
389
- with gr.Row():
390
- with gr.Column(scale=1, min_width=240, elem_classes="sidebar"):
391
- gr.HTML(SIDEBAR)
392
-
393
- with gr.Column(scale=5, elem_classes="main-wrapper"):
 
 
394
  gr.HTML("""
395
- <h2 class="page-title">Enhance <span>Sentinel-2</span> Satellite Images</h2>
396
- <p class="page-subtitle">Upload your Sentinel-2 image (GeoTIFF, TIFF, JP2, or PNG) and use AI to generate a high-resolution version.</p>
 
 
397
  """)
398
-
399
  with gr.Row():
400
- with gr.Column(scale=4, elem_classes="upload-card"):
 
401
  input_image = gr.File(
402
  label="Drag & drop your satellite image here",
403
  file_count="multiple",
404
- file_types=["image", ".tif", ".tiff", ".jp2"]
 
405
  )
406
-
 
 
 
 
 
 
407
  with gr.Column(scale=3):
408
- with gr.Group(elem_classes="model-card"):
409
- gr.HTML("<div class='model-card-title'>Model Selection</div>")
410
- model_selector = gr.Dropdown(
411
- choices=["HAT-SAT (Recommended)", "ESRGAN (Baseline)"],
412
- value="HAT-SAT (Recommended)",
413
- show_label=False,
414
- container=False
415
- )
416
- gr.HTML("""
417
- <div class="model-info-box">
418
- <svg width="20" height="20" fill="currentColor" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg>
419
- <span><strong>HAT-SAT:</strong> State-of-the-art model for satellite image super-resolution with high detail and spectral consistency.</span>
420
- </div>
421
- """)
 
 
 
 
 
 
422
  enhance_btn = gr.Button("✨ Enhance Image", elem_id="enhance-btn")
423
- gr.HTML("<div style='text-align:center; font-size:0.85rem; color:#94a3b8; margin-top:8px;'>Processing may take a few moments...</div>")
424
-
425
- with gr.Column(scale=3, elem_classes="features-card"):
426
- gr.HTML(WHY_USE_US)
427
-
428
- # Results Section
429
- gr.HTML("<div class='results-header'>Results</div>")
430
-
 
431
  with gr.Row():
432
- with gr.Column(scale=4, elem_classes="image-card"):
433
- original_image = gr.Image(label="Original (Sentinel-2, 10m)", type="pil", interactive=False)
434
-
435
- with gr.Column(scale=4, elem_classes="image-card"):
436
- enhanced_image = gr.Image(label="Enhanced (HAT-SAT, 2x)", type="pil", interactive=False)
437
-
438
- with gr.Column(scale=3, elem_classes="download-col"):
439
- gr.HTML("<div style='font-weight:700; font-size:1.05rem; color:#0f172a; margin-bottom:4px;'>Download & Share</div>")
440
-
441
- download_png = gr.DownloadButton("πŸ“₯ Download Enhanced Image", elem_classes="btn-primary")
442
- download_tiff = gr.DownloadButton("πŸ“„ Download as GeoTIFF", elem_classes="btn-outline")
443
- compare_btn = gr.Button("πŸ” Compare Images", elem_classes="btn-outline")
444
- share_btn = gr.Button("πŸ”— Share Result", elem_classes="btn-outline")
445
-
446
- gr.HTML(FOOTER)
447
-
448
- # ============================================================
449
- # EVENTS
450
- # ============================================================
451
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
452
  enhance_btn.click(
453
  fn=run_super_resolution,
454
  inputs=[input_image, model_selector],
@@ -456,11 +945,10 @@ with gr.Blocks(theme=gr.themes.Base(), css=CSS) as demo:
456
  show_progress="full",
457
  )
458
 
459
- # Interactive elements that don't do anything functionally but can show alerts
460
- def show_alert():
461
  gr.Info("This feature is coming soon!")
462
- compare_btn.click(fn=show_alert)
463
- share_btn.click(fn=show_alert)
464
 
465
 
466
  # ============================================================
 
63
  # ============================================================
64
 
65
  CSS = """
66
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');
67
+
68
+ *, *::before, *::after { box-sizing: border-box; }
69
 
70
  body, .gradio-container {
71
  font-family: 'Inter', sans-serif !important;
72
+ background-color: #f0f4f8 !important;
73
+ margin: 0 !important;
74
+ padding: 0 !important;
75
  }
76
 
 
77
  footer { display: none !important; }
78
  .gradio-container { max-width: 100% !important; padding: 0 !important; margin: 0 !important; }
79
+ .main { padding: 0 !important; }
80
 
81
+ /* ── TOP NAVBAR ── */
82
  .top-nav {
83
+ background: linear-gradient(135deg, #0a2540 0%, #0e4a6e 40%, #1a6b5a 100%);
84
+ background-size: cover;
85
+ padding: 18px 40px;
86
+ display: flex;
87
+ justify-content: space-between;
88
+ align-items: center;
89
+ position: relative;
90
+ overflow: hidden;
91
+ min-height: 90px;
92
+ border-bottom: 2px solid rgba(32, 201, 151, 0.3);
93
+ }
94
+ .top-nav::before {
95
+ content: '';
96
+ position: absolute;
97
+ inset: 0;
98
+ background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%2320c997' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
99
+ opacity: 0.5;
100
+ }
101
+ .nav-left {
102
+ display: flex;
103
+ align-items: center;
104
+ gap: 14px;
105
+ z-index: 1;
106
+ }
107
+ .nav-logo-wrap {
108
+ background: rgba(32, 201, 151, 0.15);
109
+ border: 1px solid rgba(32, 201, 151, 0.3);
110
+ border-radius: 12px;
111
+ padding: 8px 10px;
112
+ display: flex;
113
+ align-items: center;
114
+ justify-content: center;
115
+ }
116
+ .nav-logo-wrap svg { width: 38px; height: 38px; }
117
+ .nav-brand { display: flex; flex-direction: column; }
118
+ .nav-brand-name {
119
+ font-size: 1.75rem;
120
+ font-weight: 800;
121
+ color: #20c997;
122
+ line-height: 1;
123
+ letter-spacing: -0.5px;
124
+ margin: 0;
125
+ }
126
+ .nav-brand-name span { color: #ffffff; }
127
+ .nav-brand-sub {
128
+ font-size: 0.78rem;
129
+ color: rgba(255,255,255,0.65);
130
+ margin: 3px 0 0;
131
+ font-weight: 400;
132
+ letter-spacing: 0.2px;
133
+ }
134
+ .nav-brand-tagline {
135
+ font-size: 0.72rem;
136
+ color: rgba(255,255,255,0.45);
137
+ margin: 1px 0 0;
138
+ font-style: italic;
139
+ }
140
+ .nav-center {
141
+ display: flex;
142
+ gap: 28px;
143
+ align-items: center;
144
+ z-index: 1;
145
+ }
146
+ .nav-center a {
147
+ color: rgba(255,255,255,0.80);
148
+ text-decoration: none;
149
+ font-size: 0.9rem;
150
+ font-weight: 500;
151
+ padding-bottom: 2px;
152
+ transition: color 0.2s;
153
+ border-bottom: 2px solid transparent;
154
+ }
155
+ .nav-center a:hover { color: #fff; }
156
+ .nav-center a.active {
157
+ color: #fff;
158
+ border-bottom-color: #20c997;
159
+ padding-bottom: 2px;
160
+ }
161
+ .nav-right {
162
+ display: flex;
163
+ align-items: center;
164
+ gap: 20px;
165
+ z-index: 1;
166
+ }
167
+ .nav-quote {
168
+ text-align: right;
169
+ color: rgba(255,255,255,0.65);
170
+ font-size: 0.78rem;
171
+ font-style: italic;
172
+ line-height: 1.5;
173
+ }
174
+ .nav-quote strong { color: rgba(255,255,255,0.85); font-style: normal; }
175
+ .nav-cta {
176
+ background: #20c997;
177
+ color: #0a2540 !important;
178
+ padding: 10px 22px;
179
+ border-radius: 8px;
180
+ font-weight: 700;
181
+ font-size: 0.9rem;
182
+ text-decoration: none;
183
+ white-space: nowrap;
184
+ transition: background 0.2s, transform 0.15s;
185
+ border: none;
186
+ display: inline-block;
187
+ }
188
+ .nav-cta:hover { background: #12b886; transform: translateY(-1px); }
189
+
190
+ /* ── BODY LAYOUT ── */
191
+ .body-layout {
192
  display: flex;
193
+ min-height: calc(100vh - 90px - 64px);
194
+ background: #f0f4f8;
195
+ }
196
+
197
+ /* ── SIDEBAR ── */
198
+ .sidebar-wrap {
199
+ width: 220px;
200
+ min-width: 220px;
201
+ background: #ffffff;
202
+ border-right: 1px solid #e2e8f0;
203
+ display: flex;
204
+ flex-direction: column;
205
  justify-content: space-between;
206
+ padding: 24px 14px 24px;
207
+ flex-shrink: 0;
208
+ }
209
+ .sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
210
+ .sb-item {
211
+ display: flex;
212
  align-items: center;
213
+ gap: 12px;
214
+ padding: 11px 14px;
215
+ border-radius: 10px;
216
+ color: #64748b;
217
+ text-decoration: none;
218
+ font-size: 0.9rem;
219
+ font-weight: 500;
220
+ transition: background 0.15s, color 0.15s;
221
+ cursor: pointer;
222
+ }
223
+ .sb-item svg { width: 18px; height: 18px; flex-shrink: 0; }
224
+ .sb-item:hover { background: #f1f5f9; color: #1e293b; }
225
+ .sb-item.active {
226
+ background: #e6faf4;
227
+ color: #0e7c5a;
228
+ font-weight: 600;
229
+ }
230
+ .sb-item.active svg { color: #20c997; }
231
+ .sb-badge {
232
+ margin-left: auto;
233
+ background: #20c997;
234
+ color: #fff;
235
+ font-size: 0.65rem;
236
+ font-weight: 700;
237
+ padding: 2px 7px;
238
+ border-radius: 20px;
239
+ letter-spacing: 0.3px;
240
+ }
241
+ .sidebar-globe {
242
+ background: linear-gradient(135deg, #e6faf4 0%, #dbeafe 100%);
243
+ border-radius: 16px;
244
+ padding: 20px 16px;
245
+ text-align: center;
246
+ display: flex;
247
+ flex-direction: column;
248
+ align-items: center;
249
+ gap: 10px;
250
+ }
251
+ .sidebar-globe svg { width: 44px; height: 44px; }
252
+ .sidebar-globe-text {
253
+ font-size: 0.82rem;
254
+ font-weight: 600;
255
+ color: #334155;
256
+ line-height: 1.5;
257
+ }
258
+
259
+ /* ── MAIN AREA ── */
260
+ .main-area {
261
+ flex: 1;
262
+ padding: 32px 36px 40px;
263
+ min-width: 0;
264
+ }
265
+
266
+ /* Page Title */
267
+ .page-title {
268
+ font-size: 2rem;
269
+ font-weight: 800;
270
+ color: #0f172a;
271
+ margin: 0 0 6px;
272
+ letter-spacing: -0.5px;
273
+ }
274
+ .page-title em {
275
+ color: #20c997;
276
+ font-style: normal;
277
+ }
278
+ .page-subtitle {
279
+ font-size: 0.95rem;
280
+ color: #64748b;
281
+ margin: 0 0 24px;
282
+ font-weight: 400;
283
+ }
284
+
285
+ /* ── INPUT ROW ── */
286
+ .input-row {
287
+ display: grid;
288
+ grid-template-columns: 1fr 280px 240px;
289
+ gap: 20px;
290
+ margin-bottom: 24px;
291
+ }
292
+
293
+ /* Upload Card */
294
+ .upload-panel {
295
+ background: white;
296
+ border: 2px dashed #cbd5e1;
297
+ border-radius: 16px;
298
+ padding: 36px 28px;
299
+ display: flex;
300
+ flex-direction: column;
301
+ align-items: center;
302
+ justify-content: center;
303
+ text-align: center;
304
+ min-height: 240px;
305
+ transition: border-color 0.2s;
306
+ cursor: pointer;
307
+ }
308
+ .upload-panel:hover { border-color: #20c997; }
309
+ .upload-icon-wrap {
310
+ width: 68px; height: 68px;
311
+ background: #e6faf4;
312
+ border-radius: 50%;
313
+ display: flex; align-items: center; justify-content: center;
314
+ margin-bottom: 16px;
315
+ }
316
+ .upload-icon-wrap svg { width: 32px; height: 32px; color: #20c997; }
317
+ .upload-title {
318
+ font-size: 1rem;
319
+ font-weight: 600;
320
+ color: #1e293b;
321
+ margin: 0 0 4px;
322
+ }
323
+ .upload-or { font-size: 0.85rem; color: #94a3b8; margin: 8px 0; }
324
+ .upload-btn-fake {
325
+ background: #1a6b9a;
326
  color: white;
327
+ padding: 10px 24px;
328
+ border-radius: 8px;
329
+ font-weight: 600;
330
+ font-size: 0.9rem;
331
+ display: inline-block;
332
+ margin-bottom: 14px;
333
+ letter-spacing: 0.1px;
334
+ }
335
+ .upload-formats {
336
+ font-size: 0.8rem;
337
+ color: #94a3b8;
338
+ line-height: 1.6;
339
+ }
340
+
341
+ /* Override Gradio file upload appearance */
342
+ .upload-card .wrap { min-height: 240px !important; }
343
+ .upload-card { background: white !important; border: 2px dashed #cbd5e1 !important; border-radius: 16px !important; }
344
+ .upload-card:hover { border-color: #20c997 !important; }
345
+
346
+ /* Model Panel */
347
+ .model-panel {
348
+ background: white;
349
+ border-radius: 16px;
350
+ border: 1px solid #e2e8f0;
351
+ padding: 20px;
352
+ display: flex;
353
+ flex-direction: column;
354
+ gap: 14px;
355
+ box-shadow: 0 1px 8px rgba(0,0,0,0.04);
356
+ }
357
+ .model-label {
358
+ font-size: 0.88rem;
359
+ font-weight: 700;
360
+ color: #1e293b;
361
+ text-transform: uppercase;
362
+ letter-spacing: 0.5px;
363
+ }
364
+ .model-badge-row { display: flex; align-items: center; gap: 8px; }
365
+ .model-best-badge {
366
+ background: #dcfce7;
367
+ color: #166534;
368
+ font-size: 0.7rem;
369
+ font-weight: 700;
370
+ padding: 3px 9px;
371
+ border-radius: 20px;
372
+ letter-spacing: 0.3px;
373
+ }
374
+ .model-info {
375
+ background: #eff6ff;
376
+ border-left: 3px solid #3b82f6;
377
+ padding: 10px 12px;
378
+ border-radius: 0 8px 8px 0;
379
+ font-size: 0.8rem;
380
+ color: #1e40af;
381
+ line-height: 1.55;
382
+ }
383
+ .model-info strong { color: #1e3a8a; }
384
+
385
+ #enhance-btn {
386
+ background: linear-gradient(135deg, #10b981 0%, #20c997 100%) !important;
387
+ color: white !important;
388
+ font-weight: 700 !important;
389
+ font-size: 1rem !important;
390
+ padding: 14px !important;
391
+ border-radius: 10px !important;
392
+ border: none !important;
393
+ width: 100%;
394
+ letter-spacing: 0.2px;
395
+ box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35) !important;
396
+ transition: all 0.2s !important;
397
+ }
398
+ #enhance-btn:hover {
399
+ box-shadow: 0 6px 20px rgba(16, 185, 129, 0.45) !important;
400
+ transform: translateY(-1px) !important;
401
+ }
402
+ .processing-hint {
403
+ font-size: 0.78rem;
404
+ color: #94a3b8;
405
+ text-align: center;
406
+ margin-top: -4px;
407
+ font-style: italic;
408
+ }
409
+
410
+ /* Why Use Panel */
411
+ .why-panel {
412
+ background: white;
413
+ border-radius: 16px;
414
+ border: 1px solid #e2e8f0;
415
+ padding: 20px;
416
+ box-shadow: 0 1px 8px rgba(0,0,0,0.04);
417
+ }
418
+ .why-title {
419
+ font-size: 0.88rem;
420
+ font-weight: 700;
421
+ color: #1e293b;
422
+ text-transform: uppercase;
423
+ letter-spacing: 0.5px;
424
+ margin: 0 0 14px;
425
+ }
426
+ .why-item {
427
+ display: flex;
428
+ align-items: flex-start;
429
+ gap: 10px;
430
+ padding: 8px 0;
431
+ border-bottom: 1px solid #f1f5f9;
432
+ font-size: 0.845rem;
433
+ color: #475569;
434
+ font-weight: 500;
435
+ line-height: 1.4;
436
+ }
437
+ .why-item:last-child { border-bottom: none; }
438
+ .why-item svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
439
+
440
+ /* ── RESULTS SECTION ── */
441
+ .results-title {
442
+ font-size: 1.25rem;
443
+ font-weight: 700;
444
+ color: #0f172a;
445
+ margin: 8px 0 18px;
446
+ display: flex;
447
+ align-items: center;
448
+ gap: 10px;
449
+ }
450
+ .results-title::after {
451
+ content: '';
452
+ flex: 1;
453
+ height: 1px;
454
+ background: #e2e8f0;
455
+ }
456
+
457
+ .results-row {
458
+ display: grid;
459
+ grid-template-columns: 1fr 1fr 220px;
460
+ gap: 20px;
461
+ align-items: start;
462
+ }
463
+
464
+ .img-card {
465
+ background: white;
466
+ border: 1px solid #e2e8f0;
467
+ border-radius: 16px;
468
+ overflow: hidden;
469
+ box-shadow: 0 2px 12px rgba(0,0,0,0.05);
470
+ }
471
+ .img-card-header {
472
+ display: flex;
473
+ align-items: center;
474
+ justify-content: space-between;
475
+ padding: 12px 16px;
476
+ border-bottom: 1px solid #f1f5f9;
477
+ }
478
+ .img-card-label {
479
+ font-size: 0.82rem;
480
+ font-weight: 600;
481
+ color: #475569;
482
+ display: flex;
483
+ align-items: center;
484
+ gap: 8px;
485
+ }
486
+ .img-label-dot {
487
+ width: 8px; height: 8px;
488
+ border-radius: 50%;
489
+ flex-shrink: 0;
490
+ }
491
+ .img-label-dot.original { background: #94a3b8; }
492
+ .img-label-dot.enhanced { background: #20c997; }
493
+
494
+ /* Gradio image overrides */
495
+ .result-img-wrap { padding: 0 !important; }
496
+ .result-img-wrap .svelte-1uydkzt { border-radius: 0 0 16px 16px !important; }
497
+
498
+ /* Download Panel */
499
+ .dl-panel {
500
+ background: white;
501
+ border: 1px solid #e2e8f0;
502
+ border-radius: 16px;
503
+ padding: 20px;
504
+ display: flex;
505
+ flex-direction: column;
506
+ gap: 10px;
507
+ box-shadow: 0 2px 12px rgba(0,0,0,0.05);
508
+ }
509
+ .dl-title {
510
+ font-size: 0.88rem;
511
+ font-weight: 700;
512
+ color: #1e293b;
513
+ text-transform: uppercase;
514
+ letter-spacing: 0.5px;
515
+ margin-bottom: 4px;
516
+ }
517
+ #dl-png-btn {
518
+ background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
519
+ color: white !important;
520
+ font-weight: 600 !important;
521
+ font-size: 0.88rem !important;
522
+ padding: 12px 14px !important;
523
+ border-radius: 9px !important;
524
+ border: none !important;
525
+ width: 100%;
526
+ box-shadow: 0 3px 10px rgba(16, 185, 129, 0.3) !important;
527
+ transition: all 0.15s !important;
528
+ }
529
+ #dl-png-btn:hover { transform: translateY(-1px) !important; }
530
+
531
+ .btn-outline-custom {
532
+ background: white !important;
533
+ color: #475569 !important;
534
+ border: 1.5px solid #e2e8f0 !important;
535
+ font-size: 0.86rem !important;
536
+ font-weight: 500 !important;
537
+ padding: 11px 14px !important;
538
+ border-radius: 9px !important;
539
+ width: 100%;
540
+ transition: all 0.15s !important;
541
+ text-align: left !important;
542
+ }
543
+ .btn-outline-custom:hover {
544
+ border-color: #20c997 !important;
545
+ color: #0e7c5a !important;
546
+ background: #f0fdf9 !important;
547
+ }
548
+
549
+ /* ── FOOTER ── */
550
+ .site-footer {
551
+ background: #0a2540;
552
+ color: rgba(255,255,255,0.6);
553
+ padding: 18px 40px;
554
+ display: flex;
555
+ justify-content: space-between;
556
+ align-items: center;
557
+ font-size: 0.82rem;
558
+ }
559
+ .footer-brand { color: rgba(255,255,255,0.85); font-weight: 600; }
560
+ .footer-links { display: flex; gap: 20px; align-items: center; }
561
+ .footer-links a {
562
+ color: rgba(255,255,255,0.55);
563
+ text-decoration: none;
564
+ transition: color 0.2s;
565
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
566
  .footer-links a:hover { color: white; }
567
+ .footer-socials { display: flex; gap: 14px; align-items: center; }
568
+ .footer-socials a { color: rgba(255,255,255,0.5); transition: color 0.2s; }
569
+ .footer-socials a:hover { color: white; }
570
  """
571
 
572
  # ============================================================
 
575
 
576
  def run_super_resolution(image_path, model_choice, progress=gr.Progress()):
577
  if image_path is None:
578
+ raise gr.Error("Please upload a satellite image before running.")
579
 
580
  model_map = {"HAT-SAT (Recommended)": "hatsat", "ESRGAN (Baseline)": "esrgan"}
581
  selected_model = model_map.get(model_choice)
582
  if selected_model is None:
583
+ raise gr.Error("Please select a valid model.")
584
 
585
  if not isinstance(image_path, list):
586
  image_path = [image_path]
587
+
588
  is_tiff = False
589
+ profile = None
590
+
591
  if len(image_path) == 3:
592
  paths = [str(p) for p in image_path]
593
  if not all(p.lower().endswith(('.tif', '.tiff')) for p in paths):
594
+ raise gr.Error("When uploading multiple files, all must be TIFF files.")
595
+
596
  red_path = next((p for p in paths if "B04" in p.upper()), None)
597
  green_path = next((p for p in paths if "B03" in p.upper()), None)
598
  blue_path = next((p for p in paths if "B02" in p.upper()), None)
599
+
600
  if not (red_path and green_path and blue_path):
601
  paths = sorted(paths)
602
  blue_path, green_path, red_path = paths[0], paths[1], paths[2]
603
+
604
  try:
605
  with rasterio.open(red_path) as src_r, rasterio.open(green_path) as src_g, rasterio.open(blue_path) as src_b:
606
  profile = src_r.profile.copy()
607
  profile.update(count=3)
 
608
  if not (src_r.width == src_g.width == src_b.width and src_r.height == src_g.height == src_b.height):
609
+ raise gr.Error("Uploaded bands have mismatched dimensions.")
 
610
  r_data = src_r.read(1)
611
  g_data = src_g.read(1)
612
  b_data = src_b.read(1)
 
613
  data = np.stack([r_data, g_data, b_data], axis=-1)
614
  input_w, input_h = src_r.width, src_r.height
615
  is_tiff = True
616
+ except gr.Error:
617
+ raise
618
  except Exception as e:
619
+ raise gr.Error(f"Error reading 3-band TIFFs: {str(e)}")
620
+
621
  if data.dtype != np.uint8:
622
  data = normalize_rgb(data)
 
623
  original_image = Image.fromarray(data, mode="RGB")
624
+
625
  elif len(image_path) == 1:
626
  file_path = str(image_path[0])
627
  is_tiff = file_path.lower().endswith(('.tif', '.tiff'))
628
+
629
  if is_tiff:
630
  try:
631
  with rasterio.open(file_path) as src:
632
  profile = src.profile.copy()
633
  count = src.count
634
  if count not in [1, 3, 4]:
635
+ raise gr.Error(f"Unsupported band count: {count}. Expected 1, 3, or 4.")
636
+ if count in [3, 4]:
 
 
 
 
637
  data = src.read([1, 2, 3])
638
  data = np.transpose(data, (1, 2, 0))
639
  else:
640
  data = src.read(1)
641
  data = np.stack([data, data, data], axis=-1)
 
642
  input_w, input_h = src.width, src.height
643
+ except gr.Error:
644
+ raise
645
  except rasterio.errors.RasterioIOError:
646
+ raise gr.Error("Corrupted TIFF or unsupported format.")
647
  except Exception as e:
648
+ raise gr.Error(f"Error reading TIFF: {str(e)}")
649
+ if data.dtype != np.uint8:
 
 
 
650
  data = normalize_rgb(data)
 
651
  original_image = Image.fromarray(data, mode="RGB")
652
  else:
653
  try:
654
  original_image = Image.open(file_path).convert("RGB")
655
  input_w, input_h = original_image.size
656
  except Exception:
657
+ raise gr.Error("Could not read image file.")
658
  else:
659
+ raise gr.Error("Please upload 1 file (multiband) or 3 files (B04, B03, B02 bands).")
660
 
661
  if input_w < 16 or input_h < 16:
662
+ raise gr.Error(f"Image too small ({input_w}x{input_h}). Minimum is 16x16 pixels.")
663
  if input_w > 1024 or input_h > 1024:
664
+ raise gr.Error(f"Image too large ({input_w}x{input_h}). Maximum is 1024x1024 pixels.")
665
 
 
666
  try:
667
+ progress(0.5, desc=f"Running {selected_model} 4x super-resolution...")
668
  if selected_model == "hatsat":
669
  result = infer_hatsat(original_image)
670
  else:
 
672
  except Exception as e:
673
  raise gr.Error(f"{selected_model} inference failed: {e}")
674
 
675
+ progress(0.9, desc="Finalising output...")
676
 
 
677
  tmp_png = tempfile.NamedTemporaryFile(suffix=f"_sr_{selected_model}_4x.png", delete=False)
678
  result.save(tmp_png.name, format="PNG")
679
  tmp_png.close()
680
  out_png = tmp_png.name
681
 
682
+ if is_tiff and profile is not None:
 
683
  tmp_tiff = tempfile.NamedTemporaryFile(suffix=f"_sr_{selected_model}_4x_georef.tif", delete=False)
684
  tmp_tiff.close()
685
  save_sr_geotiff(result, profile, tmp_tiff.name, scale=4)
 
687
  else:
688
  out_tiff = None
689
 
690
+ progress(1.0, desc="Done!")
 
 
691
  return original_image, result, gr.update(value=out_png, interactive=True), gr.update(value=out_tiff, interactive=True)
692
 
693
 
694
  # ============================================================
695
+ # HTML SNIPPETS
696
  # ============================================================
697
 
698
  TOP_NAV = """
699
  <div class="top-nav">
700
+ <div class="nav-left">
701
+ <div class="nav-logo-wrap">
702
+ <svg viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
703
+ <circle cx="24" cy="24" r="10" stroke="#20c997" stroke-width="2.5"/>
704
+ <ellipse cx="24" cy="24" rx="22" ry="10" stroke="#20c997" stroke-width="2" opacity="0.5"/>
705
+ <ellipse cx="24" cy="24" rx="10" ry="22" stroke="#20c997" stroke-width="2" opacity="0.5"/>
706
+ <circle cx="24" cy="24" r="3" fill="#20c997"/>
707
+ <circle cx="38" cy="12" r="3" fill="#20c997" opacity="0.8"/>
708
+ <line x1="36.5" y1="13.5" x2="27" y2="21" stroke="#20c997" stroke-width="1.5" opacity="0.6"/>
709
+ </svg>
710
  </div>
711
+ <div class="nav-brand">
712
+ <h1 class="nav-brand-name">Senti<span>Enhance</span></h1>
713
+ <p class="nav-brand-sub">AI-Powered Super-Resolution for Sentinel-2 Imagery</p>
714
+ <p class="nav-brand-tagline">Sharper Insights for a Better Tomorrow</p>
 
 
 
715
  </div>
716
+ </div>
717
+ <div class="nav-center">
718
+ <a href="#" class="active">Home</a>
719
+ <a href="#">About</a>
720
+ <a href="#">How It Works</a>
721
+ <a href="#">Use Cases</a>
722
+ <a href="#">Contact</a>
723
+ </div>
724
+ <div class="nav-right">
725
+ <div class="nav-quote">
726
+ <em>"From Pixels to Possibilities"</em><br>
727
+ <strong>for a Smarter, Greener India 🌿</strong>
728
+ </div>
729
+ <a href="#" class="nav-cta">Get Started</a>
730
+ </div>
731
  </div>
732
  """
733
 
734
+ SIDEBAR_HTML = """
735
+ <div class="sidebar-wrap">
736
+ <div class="sidebar-nav">
737
+ <a href="#" class="sb-item active">
738
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"/></svg>
739
+ Super-Resolution
740
+ <span class="sb-badge">BETA</span>
741
+ </a>
742
+ <a href="#" class="sb-item">
743
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"/></svg>
744
+ Compare
745
+ </a>
746
+ <a href="#" class="sb-item">
747
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>
748
+ Image Gallery
749
+ </a>
750
+ <a href="#" class="sb-item">
751
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>
752
+ Documentation
753
+ </a>
754
+ <a href="#" class="sb-item">
755
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
756
+ About Project
757
+ </a>
758
+ </div>
759
+ <div class="sidebar-globe">
760
+ <svg viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg">
761
+ <circle cx="32" cy="32" r="28" stroke="#20c997" stroke-width="2"/>
762
+ <ellipse cx="32" cy="32" rx="14" ry="28" stroke="#20c997" stroke-width="1.5" opacity="0.5"/>
763
+ <line x1="4" y1="32" x2="60" y2="32" stroke="#20c997" stroke-width="1.5" opacity="0.4"/>
764
+ <line x1="32" y1="4" x2="32" y2="60" stroke="#20c997" stroke-width="1.5" opacity="0.4"/>
765
+ <ellipse cx="32" cy="32" rx="28" ry="10" stroke="#20c997" stroke-width="1.5" opacity="0.3"/>
766
+ <circle cx="20" cy="28" r="3" fill="#3b82f6" opacity="0.7"/>
767
+ <circle cx="38" cy="38" r="2" fill="#10b981" opacity="0.7"/>
768
+ </svg>
769
+ <div class="sidebar-globe-text">Satellite data<br>for a sustainable<br>future</div>
770
+ </div>
771
  </div>
772
  """
773
 
774
+ WHY_HTML = """
775
+ <div class="why-panel">
776
+ <div class="why-title">Why Use Our Platform?</div>
777
+ <div class="why-item">
778
+ <svg fill="none" stroke="#10b981" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/></svg>
779
  AI-powered super-resolution
780
+ </div>
781
+ <div class="why-item">
782
+ <svg fill="none" stroke="#3b82f6" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4"/></svg>
783
  Supports Sentinel-2 imagery
784
+ </div>
785
+ <div class="why-item">
786
+ <svg fill="none" stroke="#8b5cf6" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"/></svg>
787
  Preserves geospatial metadata
788
+ </div>
789
+ <div class="why-item">
790
+ <svg fill="none" stroke="#f59e0b" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/></svg>
791
  Easy to use web interface
792
+ </div>
793
+ <div class="why-item">
794
+ <svg fill="none" stroke="#10b981" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
795
+ Free for research &amp; education
796
+ </div>
797
  </div>
798
  """
799
 
800
+ FOOTER_HTML = """
801
+ <div class="site-footer">
802
+ <div>
803
+ <span class="footer-brand">SentiEnhance</span>
804
+ &nbsp;|&nbsp; AI for a Sustainable Planet
805
+ </div>
806
+ <div class="footer-links">
807
+ <a href="#">Privacy Policy</a>
808
+ <span>|</span>
809
+ <a href="#">Terms of Use</a>
810
+ <span>|</span>
811
+ <a href="#">Contact</a>
812
+ </div>
813
+ <div class="footer-socials">
814
+ <a href="#" title="LinkedIn"><svg width="18" height="18" fill="currentColor" viewBox="0 0 24 24"><path d="M19 0h-14c-2.761 0-5 2.239-5 5v14c0 2.761 2.239 5 5 5h14c2.762 0 5-2.239 5-5v-14c0-2.761-2.238-5-5-5zm-11 19h-3v-11h3v11zm-1.5-12.268c-.966 0-1.75-.79-1.75-1.764s.784-1.764 1.75-1.764 1.75.79 1.75 1.764-.783 1.764-1.75 1.764zm13.5 12.268h-3v-5.604c0-3.368-4-3.113-4 0v5.604h-3v-11h3v1.765c1.396-2.586 7-2.777 7 2.476v6.759z"/></svg></a>
815
+ <a href="#" title="GitHub"><svg width="18" height="18" fill="currentColor" viewBox="0 0 24 24"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg></a>
816
+ <a href="#" title="YouTube"><svg width="18" height="18" fill="currentColor" viewBox="0 0 24 24"><path d="M23.495 6.205a3.007 3.007 0 00-2.088-2.088c-1.87-.501-9.396-.501-9.396-.501s-7.507-.01-9.396.501A3.007 3.007 0 00.527 6.205a31.247 31.247 0 00-.522 5.805 31.247 31.247 0 00.522 5.783 3.007 3.007 0 002.088 2.088c1.868.502 9.396.502 9.396.502s7.506 0 9.396-.502a3.007 3.007 0 002.088-2.088 31.247 31.247 0 00.5-5.783 31.247 31.247 0 00-.5-5.805zM9.609 15.601V8.408l6.264 3.602z"/></svg></a>
817
+ </div>
818
  </div>
819
  """
820
 
 
822
  # APP LAYOUT
823
  # ============================================================
824
 
825
+ with gr.Blocks(css=CSS, title="SentiEnhance β€” AI Satellite Super-Resolution") as demo:
826
+
827
  gr.HTML(TOP_NAV)
828
+
829
+ with gr.Row(equal_height=True):
830
+ # ── SIDEBAR ──
831
+ with gr.Column(scale=0, min_width=220, elem_id="sidebar-col"):
832
+ gr.HTML(SIDEBAR_HTML)
833
+
834
+ # ── MAIN CONTENT ──
835
+ with gr.Column(scale=1, elem_id="main-col"):
836
  gr.HTML("""
837
+ <div class="main-area">
838
+ <h2 class="page-title">Enhance <em>Sentinel-2</em> Satellite Images</h2>
839
+ <p class="page-subtitle">Upload your Sentinel-2 image (GeoTIFF, TIFF, JP2, or PNG) and use AI to generate a high-resolution version.</p>
840
+ </div>
841
  """)
842
+
843
  with gr.Row():
844
+ # Upload
845
+ with gr.Column(scale=5):
846
  input_image = gr.File(
847
  label="Drag & drop your satellite image here",
848
  file_count="multiple",
849
+ file_types=["image", ".tif", ".tiff", ".jp2"],
850
+ elem_classes="upload-card"
851
  )
852
+ gr.HTML("""
853
+ <div style="text-align:center; font-size:0.8rem; color:#94a3b8; margin-top:8px;">
854
+ Supported formats: .tif, .tiff, .jp2, .png &nbsp;(Sentinel-2 imagery)
855
+ </div>
856
+ """)
857
+
858
+ # Model + Enhance
859
  with gr.Column(scale=3):
860
+ gr.HTML("""
861
+ <div class="model-panel">
862
+ <div class="model-label">Model Selection</div>
863
+ </div>
864
+ """)
865
+ model_selector = gr.Dropdown(
866
+ choices=["HAT-SAT (Recommended)", "ESRGAN (Baseline)"],
867
+ value="HAT-SAT (Recommended)",
868
+ show_label=False,
869
+ container=False
870
+ )
871
+ gr.HTML("""
872
+ <div style="display:flex;align-items:center;gap:8px;margin:6px 0 2px;">
873
+ <span style="font-size:0.78rem;color:#64748b;">Selected Model:</span>
874
+ <span class="model-best-badge">Best Quality</span>
875
+ </div>
876
+ <div class="model-info">
877
+ <strong>HAT-SAT:</strong> State-of-the-art model for satellite image super-resolution with high detail and spectral consistency.
878
+ </div>
879
+ """)
880
  enhance_btn = gr.Button("✨ Enhance Image", elem_id="enhance-btn")
881
+ gr.HTML('<div class="processing-hint">Processing may take a few moments...</div>')
882
+
883
+ # Why Use Us
884
+ with gr.Column(scale=3):
885
+ gr.HTML(WHY_HTML)
886
+
887
+ # ── RESULTS ──
888
+ gr.HTML('<div class="results-title">Results</div>')
889
+
890
  with gr.Row():
891
+ with gr.Column(scale=5, elem_classes="img-card"):
892
+ gr.HTML("""
893
+ <div class="img-card-header">
894
+ <div class="img-card-label">
895
+ <span class="img-label-dot original"></span>
896
+ Original (Sentinel-2, 10m)
897
+ </div>
898
+ </div>
899
+ """)
900
+ original_image = gr.Image(
901
+ label="",
902
+ type="pil",
903
+ interactive=False,
904
+ show_label=False,
905
+ elem_classes="result-img-wrap"
906
+ )
907
+
908
+ with gr.Column(scale=5, elem_classes="img-card"):
909
+ gr.HTML("""
910
+ <div class="img-card-header">
911
+ <div class="img-card-label">
912
+ <span class="img-label-dot enhanced"></span>
913
+ Enhanced (HAT-SAT, 4x)
914
+ </div>
915
+ </div>
916
+ """)
917
+ enhanced_image = gr.Image(
918
+ label="",
919
+ type="pil",
920
+ interactive=False,
921
+ show_label=False,
922
+ elem_classes="result-img-wrap"
923
+ )
924
+
925
+ with gr.Column(scale=3):
926
+ gr.HTML('<div class="dl-panel"><div class="dl-title">Download &amp; Share</div></div>')
927
+ download_png = gr.DownloadButton(
928
+ "πŸ“₯ Download Enhanced Image",
929
+ elem_id="dl-png-btn"
930
+ )
931
+ download_tiff = gr.DownloadButton(
932
+ "πŸ“„ Download as GeoTIFF",
933
+ elem_classes="btn-outline-custom"
934
+ )
935
+ compare_btn = gr.Button("πŸ” Compare Images", elem_classes="btn-outline-custom")
936
+ share_btn = gr.Button("πŸ”— Share Result", elem_classes="btn-outline-custom")
937
+
938
+ gr.HTML(FOOTER_HTML)
939
+
940
+ # ── EVENTS ──
941
  enhance_btn.click(
942
  fn=run_super_resolution,
943
  inputs=[input_image, model_selector],
 
945
  show_progress="full",
946
  )
947
 
948
+ def show_soon():
 
949
  gr.Info("This feature is coming soon!")
950
+ compare_btn.click(fn=show_soon)
951
+ share_btn.click(fn=show_soon)
952
 
953
 
954
  # ============================================================