Spaces:
Paused
Paused
test gradio
Browse files
app.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
-
import torch
|
3 |
-
# from diffusers import StableDiffusion3ControlNetPipeline, SD3ControlNetModel, UniPCMultistepScheduler
|
4 |
-
from diffusers import StableDiffusionXLPipeline,T2IAdapter
|
5 |
from huggingface_hub import login
|
6 |
import os
|
7 |
import spaces
|
|
|
|
|
8 |
from diffusers.utils import load_image, make_image_grid
|
9 |
-
from diffusers import StableDiffusionXLAdapterPipeline, T2IAdapter, EulerAncestralDiscreteScheduler, AutoencoderKL
|
10 |
|
11 |
token = os.getenv("HF_TOKEN")
|
12 |
login(token=token)
|
@@ -27,16 +25,24 @@ login(token=token)
|
|
27 |
# controlnet = SD3ControlNetModel.from_pretrained("alimama-creative/SD3-Controlnet-Softedge", torch_dtype=torch.float16)
|
28 |
|
29 |
# pipe = StableDiffusion3ControlNetPipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers", controlnet=controlnet)
|
30 |
-
adapter = T2IAdapter.from_pretrained(
|
31 |
-
|
32 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
40 |
|
41 |
pipe.to("cuda", torch.float16)
|
42 |
|
@@ -45,11 +51,15 @@ pipe.to("cuda", torch.float16)
|
|
45 |
def generate_image(prompt, reference_image, controlnet_conditioning_scale):
|
46 |
|
47 |
# Generate the image with ControlNet conditioning
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
return generated_image
|
54 |
|
55 |
# Set up Gradio interface
|
@@ -63,6 +73,7 @@ interface = gr.Interface(
|
|
63 |
outputs="image",
|
64 |
title="Image Generation with Stable Diffusion 3 medium and ControlNet",
|
65 |
description="Generates an image based on a text prompt and a reference image using Stable Diffusion 3 medium with ControlNet."
|
|
|
66 |
)
|
67 |
|
68 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
from huggingface_hub import login
|
3 |
import os
|
4 |
import spaces
|
5 |
+
import torch
|
6 |
+
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, StableDiffusionPipeline
|
7 |
from diffusers.utils import load_image, make_image_grid
|
|
|
8 |
|
9 |
token = os.getenv("HF_TOKEN")
|
10 |
login(token=token)
|
|
|
25 |
# controlnet = SD3ControlNetModel.from_pretrained("alimama-creative/SD3-Controlnet-Softedge", torch_dtype=torch.float16)
|
26 |
|
27 |
# pipe = StableDiffusion3ControlNetPipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers", controlnet=controlnet)
|
28 |
+
# adapter = T2IAdapter.from_pretrained(
|
29 |
+
# "TencentARC/t2iadapter_color_sd14v1", torch_dtype=torch.float16, varient="fp16"
|
30 |
+
# )
|
31 |
+
#
|
32 |
+
# model_id = 'stabilityai/stable-diffusion-xl-base-1.0'
|
33 |
+
# euler_a = EulerAncestralDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
|
34 |
+
# vae=AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
35 |
+
# pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
|
36 |
+
# model_id, vae=vae, adapter=adapter, scheduler=euler_a, torch_dtype=torch.float16, variant="fp16",
|
37 |
+
# )
|
38 |
|
39 |
+
|
40 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
41 |
+
"Yntec/AbsoluteReality",
|
42 |
+
torch_dtype=torch.float16)
|
43 |
+
pipe.load_ip_adapter("h94/IP-Adapter",
|
44 |
+
subfolder="models",
|
45 |
+
weight_name="ip-adapter_sd15.bin")
|
46 |
|
47 |
pipe.to("cuda", torch.float16)
|
48 |
|
|
|
51 |
def generate_image(prompt, reference_image, controlnet_conditioning_scale):
|
52 |
|
53 |
# Generate the image with ControlNet conditioning
|
54 |
+
pipe.set_ip_adapter_scale(controlnet_conditioning_scale)
|
55 |
+
generated_image = pipe(prompt=prompt,
|
56 |
+
negative_prompt="low quality",
|
57 |
+
height=768,
|
58 |
+
width=768,
|
59 |
+
ip_adapter_image=load_image(reference_image),
|
60 |
+
guidance_scale=6,
|
61 |
+
num_inference_steps=20,
|
62 |
+
num_images_per_prompt=3).images[0]
|
63 |
return generated_image
|
64 |
|
65 |
# Set up Gradio interface
|
|
|
73 |
outputs="image",
|
74 |
title="Image Generation with Stable Diffusion 3 medium and ControlNet",
|
75 |
description="Generates an image based on a text prompt and a reference image using Stable Diffusion 3 medium with ControlNet."
|
76 |
+
|
77 |
)
|
78 |
|
79 |
interface.launch()
|