Spaces:
Sleeping
Sleeping
Commit ·
449b225
1
Parent(s): 3e0ea62
🚀 Initial Release: KAO-DIFFSAT-VHR-DEMO
Browse files- .gitattributes +7 -0
- README.md +1 -1
- app.py +59 -13
- satellite_sample_input/M-33-20-D-c-4-2.jpg +3 -0
- satellite_sample_input/M-33-7-A-d-3-2.jpg +3 -0
- satellite_sample_input/M-34-56-A-b-1-4.jpg +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,10 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
# Image files
|
| 37 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
*.webp filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
*.tiff filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
*.bmp filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
title: KAO DIFFSAT Demo
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
|
|
|
| 1 |
---
|
| 2 |
title: KAO DIFFSAT Demo
|
| 3 |
+
emoji: 🛰️
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
app.py
CHANGED
|
@@ -2,7 +2,11 @@ import torch
|
|
| 2 |
import gradio as gr
|
| 3 |
from PIL import Image
|
| 4 |
from diffusers import StableDiffusionInpaintPipeline
|
|
|
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
MODEL_ID = "kaopanboonyuen/KAO-DIFFSAT-VHR-v1"
|
| 7 |
|
| 8 |
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
|
@@ -10,34 +14,76 @@ pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
|
| 10 |
torch_dtype=torch.float16
|
| 11 |
).to("cuda")
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def inpaint(image, mask, prompt):
|
| 14 |
image = image.convert("RGB")
|
| 15 |
mask = mask.convert("RGB")
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
return result
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
description = """
|
| 27 |
-
Satellite Image Inpainting
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
"""
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
demo = gr.Interface(
|
| 32 |
fn=inpaint,
|
| 33 |
inputs=[
|
| 34 |
-
gr.Image(type="pil", label="Input Image"),
|
| 35 |
-
gr.Image(type="pil", label="Mask
|
| 36 |
-
gr.Textbox(
|
|
|
|
|
|
|
|
|
|
| 37 |
],
|
| 38 |
-
outputs=gr.Image(type="pil"),
|
| 39 |
title=title,
|
| 40 |
-
description=description
|
|
|
|
|
|
|
| 41 |
)
|
| 42 |
|
| 43 |
demo.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from PIL import Image
|
| 4 |
from diffusers import StableDiffusionInpaintPipeline
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
+
# -----------------------------
|
| 8 |
+
# Model
|
| 9 |
+
# -----------------------------
|
| 10 |
MODEL_ID = "kaopanboonyuen/KAO-DIFFSAT-VHR-v1"
|
| 11 |
|
| 12 |
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
|
|
|
| 14 |
torch_dtype=torch.float16
|
| 15 |
).to("cuda")
|
| 16 |
|
| 17 |
+
pipe.enable_attention_slicing()
|
| 18 |
+
|
| 19 |
+
# -----------------------------
|
| 20 |
+
# Inpainting Function
|
| 21 |
+
# -----------------------------
|
| 22 |
def inpaint(image, mask, prompt):
|
| 23 |
image = image.convert("RGB")
|
| 24 |
mask = mask.convert("RGB")
|
| 25 |
|
| 26 |
+
with torch.autocast("cuda"):
|
| 27 |
+
result = pipe(
|
| 28 |
+
prompt=prompt,
|
| 29 |
+
image=image,
|
| 30 |
+
mask_image=mask,
|
| 31 |
+
guidance_scale=7.5,
|
| 32 |
+
num_inference_steps=30
|
| 33 |
+
).images[0]
|
| 34 |
|
| 35 |
return result
|
| 36 |
|
| 37 |
+
|
| 38 |
+
# -----------------------------
|
| 39 |
+
# Optional: Sample loader
|
| 40 |
+
# -----------------------------
|
| 41 |
+
SAMPLE_DIR = "satellite_sample_input"
|
| 42 |
+
|
| 43 |
+
def load_sample(name):
|
| 44 |
+
path = os.path.join(SAMPLE_DIR, name)
|
| 45 |
+
return Image.open(path).convert("RGB")
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# -----------------------------
|
| 49 |
+
# UI
|
| 50 |
+
# -----------------------------
|
| 51 |
+
title = "🛰️ KAO-DIFFSAT-VHR-v1"
|
| 52 |
description = """
|
| 53 |
+
**Diffusion-based Satellite Image Inpainting for Very High Resolution (VHR) Remote Sensing**
|
| 54 |
+
|
| 55 |
+
This demo showcases KAO-DIFFSAT-VHR-v1, a baseline diffusion model for reconstructing missing or corrupted satellite imagery regions.
|
| 56 |
+
|
| 57 |
+
Upload your own image or try preloaded samples.
|
| 58 |
"""
|
| 59 |
|
| 60 |
+
examples = [
|
| 61 |
+
[load_sample("M-33-7-A-d-3-2.jpg"), None,
|
| 62 |
+
"Restore missing satellite regions with realistic urban and natural structures"],
|
| 63 |
+
|
| 64 |
+
[load_sample("M-33-20-D-c-4-2.jpg"), None,
|
| 65 |
+
"High-resolution satellite inpainting with consistent geography and texture"],
|
| 66 |
+
|
| 67 |
+
[load_sample("M-34-56-A-b-1-4.jpg"), None,
|
| 68 |
+
"Reconstruct VHR remote sensing image with spatial consistency"]
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
demo = gr.Interface(
|
| 73 |
fn=inpaint,
|
| 74 |
inputs=[
|
| 75 |
+
gr.Image(type="pil", label="🛰️ Input Satellite Image"),
|
| 76 |
+
gr.Image(type="pil", label="🎯 Mask (white = inpaint region)"),
|
| 77 |
+
gr.Textbox(
|
| 78 |
+
label="Prompt",
|
| 79 |
+
value="High-resolution satellite image reconstruction with realistic land cover, buildings, and terrain consistency"
|
| 80 |
+
)
|
| 81 |
],
|
| 82 |
+
outputs=gr.Image(type="pil", label="🧠 Reconstructed Output"),
|
| 83 |
title=title,
|
| 84 |
+
description=description,
|
| 85 |
+
examples=examples,
|
| 86 |
+
allow_flagging="never"
|
| 87 |
)
|
| 88 |
|
| 89 |
demo.launch()
|
satellite_sample_input/M-33-20-D-c-4-2.jpg
ADDED
|
Git LFS Details
|
satellite_sample_input/M-33-7-A-d-3-2.jpg
ADDED
|
Git LFS Details
|
satellite_sample_input/M-34-56-A-b-1-4.jpg
ADDED
|
Git LFS Details
|