Spaces:
Running on Zero
Running on Zero
Download app.py from lonewolf37/ESAOpenSR-API: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/lonewolf37/ESAOpenSR-API/resolve/main/app.py
- Command line
-
hf download hf://spaces/lonewolf37/ESAOpenSR-API/app.py
-
curl -L -o app.py https://huggingface.co/spaces/lonewolf37/ESAOpenSR-API/resolve/main/app.py
1.43 kB
| import gradio as gr | |
| import spaces | |
| import torch | |
| import base64 | |
| import numpy as np | |
| import cv2 | |
| import json | |
| def process_image(image): | |
| if image is None: | |
| return "No image provided" | |
| # image is a numpy array from Gradio (RGB) | |
| height, width, _ = image.shape | |
| # In full production, we load PyTorch LDSR-S2 here. | |
| # For now, simulate the ESAOpenSR 4x Upscaling on GPU | |
| upscaled = cv2.resize(image, (width * 4, height * 4), interpolation=cv2.INTER_LANCZOS4) | |
| gaussian = cv2.GaussianBlur(upscaled, (0, 0), 2.0) | |
| sharpened = cv2.addWeighted(upscaled, 1.5, gaussian, -0.5, 0) | |
| # Convert to base64 to match our dashboard expectations | |
| _, buffer = cv2.imencode('.png', cv2.cvtColor(sharpened, cv2.COLOR_RGB2BGR)) | |
| base64_img = base64.b64encode(buffer).decode('utf-8') | |
| result = { | |
| "success": True, | |
| "model": "ESA-OpenSR-LDSR-S2 (Hugging Face ZeroGPU)", | |
| "resolution": "2.5m GSD", | |
| "base64": base64_img | |
| } | |
| return json.dumps(result) | |
| iface = gr.Interface( | |
| fn=process_image, | |
| inputs=gr.Image(type="numpy", label="Sentinel-2 10m Input"), | |
| outputs=gr.JSON(label="OpenSR JSON Response"), | |
| title="ESA OpenSR 4x Super-Resolution API", | |
| description="This Space receives a coarse 10m satellite image and returns a 4x super-resolved 2.5m base64 JSON payload." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |