Spaces:
Paused
Paused
File size: 2,618 Bytes
683afc3 bcbf6e0 9b01735 b12bc82 c1497a6 0737dc8 74c4e79 cd0d25d b12bc82 feede18 4fbc46c c1497a6 683afc3 cd0d25d 683afc3 bcbf6e0 cd0d25d bcbf6e0 cd0d25d 9b01735 bcbf6e0 9b01735 b12bc82 47700a0 b12bc82 8c7a7e5 b12bc82 bcbf6e0 0737dc8 74c4e79 5a5a07a 0737dc8 121ee3d 52d3f89 683afc3 9b01735 a78f2ac 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 62 63 64 65 66 67 68 69 |
import gradio as gr
import torch
# from diffusers import StableDiffusion3ControlNetPipeline, SD3ControlNetModel, UniPCMultistepScheduler
from diffusers import StableDiffusionXLPipeline,T2IAdapter
from huggingface_hub import login
import os
import spaces
from diffusers.utils import load_image, make_image_grid
from diffusers import StableDiffusionXLAdapterPipeline, T2IAdapter, EulerAncestralDiscreteScheduler, AutoencoderKL
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)
adapter = T2IAdapter.from_pretrained(
"TencentARC/t2iadapter_color_sd14v1", torch_dtype=torch.float16, varient="fp16"
)
model_id = 'stabilityai/stable-diffusion-xl-base-1.0'
euler_a = EulerAncestralDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
vae=AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
model_id, vae=vae, adapter=adapter, scheduler=euler_a, torch_dtype=torch.float16, variant="fp16",
)
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,
ip_adapter_image=load_image(reference_image),
adapter_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()
|