File size: 2,119 Bytes
683afc3
 
91e7ec6
c1497a6
0737dc8
74c4e79
cd0d25d
 
 
 
 
feede18
121ee3d
4fbc46c
c1497a6
683afc3
7d9ea7a
cd0d25d
 
 
 
 
 
 
 
 
 
feede18
683afc3
cd0d25d
 
 
 
 
0737dc8
74c4e79
5a5a07a
0737dc8
121ee3d
52d3f89
683afc3
feede18
505f3d2
7968596
8d2ed6a
683afc3
7968596
 
 
 
 
feede18
7968596
 
 
 
 
 
683afc3
7968596
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import gradio as gr
import torch
from diffusers import StableDiffusion3ControlNetPipeline, SD3ControlNetModel, UniPCMultistepScheduler
from huggingface_hub import login
import os
import spaces
from diffusers.utils import load_image, make_image_grid
import torch
from diffusers import StableDiffusionXLAdapterPipeline,T2IAdapter
from diffusers.models import T2IAdapter
from diffusers.schedulers import UniPCMultistepScheduler

# Log in to Hugging Face with your token
token = os.getenv("HF_TOKEN")
login(token=token)



# Load the T2I-Style Adapter and the SDXL pipeline
adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-style-sdxl")
pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    adapter=adapter,
)

# Set up the scheduler and device
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
pipe.to("cuda", torch.float16)

# controlnet = SD3ControlNetModel.from_pretrained("alimama-creative/SD3-Controlnet-Softedge", torch_dtype=torch.float16)
#
# pipe = StableDiffusion3ControlNetPipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers", controlnet=controlnet)
# pipe.to("cuda", torch.float16)


@spaces.GPU
def generate_image(prompt, reference_image, controlnet_conditioning_scale):

    # Generate the image with ControlNet conditioning
    generated_image = pipe(
        prompt=prompt,
        control_image=load_image(reference_image),
        controlnet_conditioning_scale=controlnet_conditioning_scale,
    ).images[0]
    return generated_image

# Set up Gradio interface
interface = gr.Interface(
    fn=generate_image,
    inputs=[
        gr.Textbox(label="Prompt"),
        gr.Image( type= "filepath",label="Reference Image (Style)"),
        gr.Slider(label="Control Net Conditioning Scale", minimum=0, maximum=1.0, step=0.1, value=0.6),
    ],
    outputs="image",
    title="Image Generation with Stable Diffusion 3 medium and ControlNet",
    description="Generates an image based on a text prompt and a reference image using Stable Diffusion 3 medium with ControlNet."
)

interface.launch()