Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import torch
|
| 4 |
+
from diffusers import AutoPipelineForImage2Image
|
| 5 |
+
|
| 6 |
+
# 1. Ładujemy model WindowSeat z Hugging Face
|
| 7 |
+
MODEL_ID = "huawei-bayerlab/windowseat-reflection-removal-v1-0"
|
| 8 |
+
|
| 9 |
+
pipe = AutoPipelineForImage2Image.from_pretrained(
|
| 10 |
+
MODEL_ID,
|
| 11 |
+
torch_dtype=torch.float16,
|
| 12 |
+
).to("cuda" if torch.cuda.is_available() else "cpu")
|
| 13 |
+
|
| 14 |
+
# 2. Funkcja, która przyjmuje jedno zdjęcie i zwraca przetworzone
|
| 15 |
+
def remove_reflection(img: Image.Image) -> Image.Image:
|
| 16 |
+
result = pipe(
|
| 17 |
+
image=img,
|
| 18 |
+
prompt="", # nie potrzebujemy promptu, model wie co robić
|
| 19 |
+
strength=1.0,
|
| 20 |
+
num_inference_steps=4,
|
| 21 |
+
guidance_scale=1.0,
|
| 22 |
+
).images[0]
|
| 23 |
+
return result
|
| 24 |
+
|
| 25 |
+
# 3. Gradio – proste API: jedno wejście (image), jedno wyjście (image)
|
| 26 |
+
demo = gr.Interface(
|
| 27 |
+
fn=remove_reflection,
|
| 28 |
+
inputs=gr.Image(type="pil"),
|
| 29 |
+
outputs=gr.Image(type="pil"),
|
| 30 |
+
title="WindowSeat Reflection Removal - API",
|
| 31 |
+
description="Upload a photo with window reflections – get cleaned version.",
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
demo.launch()
|