Upload app.py with huggingface_hub
Browse files580 unmodified lines5815825835845845855865875885895895905915925935935945955962 unmodified lines5996006016026036046056026036046056066076126086096106116166126136146156 unmodified lines6226236246296256266276281 unmodified line630631632637633634635636580 unmodified lines return Image.open(filepath).convert('RGB')
def translate_sar(image, num_steps, overlap, enhance, progress=gr.Progress()):
def translate_sar(image, num_steps, overlap, enhance):
"""Main translation function."""
global model
if model is None:
progress(0, desc="Loading model...")
print("Loading model...")
model = E3DiffHighRes()
model.load_model()
progress(0.1, desc="Processing image...")
print("Processing image...")
# Handle file upload
if isinstance(image, str):2 unmodified lines w, h = image.size
print(f"Input size: {w}x{h}")
# Progress callback
def update_progress(p):
progress(0.1 + 0.8 * p, desc=f"Translating... {int(p*100)}%")
# Translate
start = time.time()
result = model.translate_full_resolution(
image,
num_steps=num_steps,
overlap=overlap,
progress_callback=update_progress
progress_callback=None
)
elapsed = time.time() - start
progress(0.9, desc="Post-processing...")
print("Post-processing...")
# Convert to PIL
result_pil = Image.fromarray((result * 255).astype(np.uint8))6 unmodified lines tiff_path = tempfile.mktemp(suffix='.tiff')
result_pil.save(tiff_path, format='TIFF', compression='lzw')
progress(1.0, desc="Complete!")
print("Complete!")
info = f"Processed in {elapsed:.1f}s | Output: {result_pil.size[0]}x{result_pil.size[1]}"
1 unmodified line
# Create Gradio interface
with gr.Blocks(title="E3Diff: SAR-to-Optical Translation", theme=gr.themes.Soft()) as demo:
with gr.Blocks(title="E3Diff: SAR-to-Optical Translation") as demo:
gr.Markdown("""
# 🛰️ E3Diff: High-Resolution SAR-to-Optical Translation
app.py+7-11