vsvipul119 commited on
Commit
3bfa7dd
·
verified ·
1 Parent(s): 23e5c0a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
4
+ from PIL import Image
5
+
6
+ def load_model():
7
+ controlnet = ControlNetModel.from_pretrained(
8
+ "Yuanshi/OminiControl",
9
+ torch_dtype=torch.float16,
10
+ use_safetensors=True
11
+ )
12
+
13
+ pipe = StableDiffusionControlNetPipeline.from_pretrained(
14
+ "runwayml/stable-diffusion-v1-5",
15
+ controlnet=controlnet,
16
+ torch_dtype=torch.float16,
17
+ safety_checker=None
18
+ ).to("cuda" if torch.cuda.is_available() else "cpu")
19
+ return pipe
20
+
21
+ def generate(image, prompt, resolution):
22
+ pipe = load_model()
23
+ output = pipe(
24
+ prompt=prompt,
25
+ image=image,
26
+ num_inference_steps=20,
27
+ controlnet_conditioning_scale=1.0,
28
+ width=resolution,
29
+ height=resolution
30
+ ).images[0]
31
+ return output
32
+
33
+ # Create Gradio interface
34
+ demo = gr.Interface(
35
+ fn=generate,
36
+ inputs=[
37
+ gr.Image(type="pil", label="Upload Image"),
38
+ gr.Textbox(label="Enter your prompt"),
39
+ gr.Radio(choices=[512, 1024], value=512, label="Resolution")
40
+ ],
41
+ outputs=gr.Image(label="Generated Image"),
42
+ title="OminiControl Image Editor",
43
+ description="Upload an image and provide a prompt to edit it."
44
+ )
45
+
46
+ if __name__ == "__main__":
47
+ demo.launch()