File size: 1,005 Bytes
f570e61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import torch
import gradio as gr
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
from PIL import Image

# Load ControlNet model
controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_inpaint", torch_dtype=torch.float16)

# Load Stable Diffusion Pipeline
pipe = StableDiffusionControlNetPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    controlnet=controlnet,
    torch_dtype=torch.float16
).to("cuda")

# Function to process images
def remove_filter(image):
    prompt = "restore the original colors and details, remove the filter"
    output = pipe(prompt, image=image).images[0]
    return output

# Gradio Interface
iface = gr.Interface(
    fn=remove_filter,
    inputs=gr.Image(type="pil"),
    outputs=gr.Image(type="pil"),
    title="Filter Removal using ControlNet",
    description="Upload a filtered image, and this app will attempt to restore the original image.",
)

# Launch the app
if __name__ == "__main__":
    iface.launch()