sphinxsolution commited on
Commit
7aa3501
·
verified ·
1 Parent(s): c7b4c0e

created app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
4
+ from PIL import Image
5
+
6
+ # Load ControlNet model
7
+ controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_inpaint", torch_dtype=torch.float16)
8
+
9
+ # Load Stable Diffusion Pipeline
10
+ pipe = StableDiffusionControlNetPipeline.from_pretrained(
11
+ "runwayml/stable-diffusion-v1-5",
12
+ controlnet=controlnet,
13
+ torch_dtype=torch.float16
14
+ ).to("cuda")
15
+
16
+ # Function to process images
17
+ def remove_filter(image, prompt):
18
+ output = pipe(prompt=prompt, image=image).images[0]
19
+ return output
20
+
21
+ # Gradio Interface
22
+ iface = gr.Interface(
23
+ fn=remove_filter,
24
+ inputs=[
25
+ gr.Image(type="pil"), # Image input
26
+ gr.Textbox(label="Custom Prompt", placeholder="Enter a custom prompt", default="restore the original colors and details, remove the filter") # Textbox for the prompt
27
+ ],
28
+ outputs=gr.Image(type="pil"),
29
+ title="Filter Removal using ControlNet",
30
+ description="Upload a filtered image and provide a prompt to restore the original image.",
31
+ )
32
+
33
+ # Launch the app
34
+ if __name__ == "__main__":
35
+ iface.launch()