Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from controlnet_aux import OpenposeDetector
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCMultistepScheduler
|
| 5 |
+
import torch
|
| 6 |
+
from controlnet_aux import OpenposeDetector
|
| 7 |
+
from diffusers.utils import load_image
|
| 8 |
+
|
| 9 |
+
#Models
|
| 10 |
+
openpose = OpenposeDetector.from_pretrained('lllyasviel/ControlNet')
|
| 11 |
+
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-openpose", torch_dtype=torch.float16)
|
| 12 |
+
pipe = StableDiffusionControlNetPipeline.from_pretrained("/content/drive/MyDrive/hack/800", controlnet=controlnet, safety_checker=None, torch_dtype=torch.float16)
|
| 13 |
+
|
| 14 |
+
#optimizations
|
| 15 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
| 16 |
+
pipe.enable_xformers_memory_efficient_attention()
|
| 17 |
+
pipe.enable_model_cpu_offload()
|
| 18 |
+
|
| 19 |
+
def generate(image,prompt):
|
| 20 |
+
image = openpose(image)
|
| 21 |
+
print(image)
|
| 22 |
+
image = pipe(prompt, image, num_inference_steps=20).images[0]
|
| 23 |
+
return image
|
| 24 |
+
|
| 25 |
+
gr.Interface(fn=generate, inputs=["image","text"], outputs="image").launch(share=True)
|
| 26 |
+
|