Upload app.py with huggingface_hub
Browse files21 unmodified lines222324252627132 unmodified lines160161162163164165508 unmodified lines67467567667767867968068129 unmodified lines71171271371471571621 unmodified linesfrom functools import partialfrom huggingface_hub import hf_hub_download# ============================================================================# SoftPool Implementation (Pure PyTorch)# ============================================================================132 unmodified linesh = self.block1(x)h = self.noise_func(h, time_emb)h = self.block2(h)h = self.c_func(c) + hreturn h + self.res_conv(x)508 unmodified linesreturn Image.open(filepath).convert('RGB')def translate_sar(file, num_steps, overlap, enhance_output):"""Main translation function."""global processorif file is None:29 unmodified linesreturn result_pil, tiff_path, info# Create interfacewith gr.Blocks(title="E3Diff: SAR-to-Optical Translation") as demo:gr.Markdown("""21 unmodified lines2223242526272829303132333435132 unmodified lines168169170171172173174175176508 unmodified lines68568668768868969069169229 unmodified lines72272372472572672772872973073173273373421 unmodified linesfrom functools import partialfrom huggingface_hub import hf_hub_download# ZeroGPU supporttry:import spacesGPU_AVAILABLE = Trueexcept ImportError:GPU_AVAILABLE = Falsespaces = None# ============================================================================# SoftPool Implementation (Pure PyTorch)# ============================================================================132 unmodified linesh = self.block1(x)h = self.noise_func(h, time_emb)h = self.block2(h)# Resize condition features to match spatial sizeif c.shape[2:] != h.shape[2:]:c = F.interpolate(c, size=h.shape[2:], mode='bilinear', align_corners=False)h = self.c_func(c) + hreturn h + self.res_conv(x)508 unmodified linesreturn Image.open(filepath).convert('RGB')def _translate_sar_impl(file, num_steps, overlap, enhance_output):"""Main translation function implementation."""global processorif file is None:29 unmodified linesreturn result_pil, tiff_path, info# Apply GPU decorator if availableif GPU_AVAILABLE and spaces is not None:translate_sar = spaces.GPU(duration=300)(_translate_sar_impl)else:translate_sar = _translate_sar_impl# Create interfacewith gr.Blocks(title="E3Diff: SAR-to-Optical Translation") as demo:gr.Markdown("""
app.py+20-2