Spaces:
Paused
Paused
test gradio
Browse files
app.py
CHANGED
|
@@ -1,29 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
from diffusers import
|
| 4 |
from huggingface_hub import login
|
| 5 |
import os
|
| 6 |
|
| 7 |
-
# Log in to Hugging Face with token
|
| 8 |
token = os.getenv("HF_TOKEN")
|
| 9 |
login(token=token)
|
| 10 |
|
| 11 |
-
# Model IDs for
|
| 12 |
-
model_id = "
|
| 13 |
-
controlnet_id = "lllyasviel/control_v11p_sd15_inpaint"
|
| 14 |
|
| 15 |
-
# Load ControlNet and Stable Diffusion
|
| 16 |
-
controlnet = ControlNetModel.from_pretrained(controlnet_id, torch_dtype=torch.
|
| 17 |
-
pipe =
|
|
|
|
|
|
|
| 18 |
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
| 19 |
pipe = pipe.to("cuda") if torch.cuda.is_available() else pipe
|
| 20 |
|
| 21 |
-
# Gradio interface function
|
| 22 |
def generate_image(prompt, reference_image):
|
| 23 |
-
# Prepare the reference image
|
| 24 |
reference_image = reference_image.convert("RGB").resize((512, 512))
|
| 25 |
|
| 26 |
-
# Generate the image
|
| 27 |
generated_image = pipe(
|
| 28 |
prompt=prompt,
|
| 29 |
image=reference_image,
|
|
@@ -41,8 +43,8 @@ interface = gr.Interface(
|
|
| 41 |
gr.Image(type="pil", label="Reference Image (Style)")
|
| 42 |
],
|
| 43 |
outputs="image",
|
| 44 |
-
title="Image Generation with Stable Diffusion
|
| 45 |
-
description="Generates an image based on a text prompt and
|
| 46 |
)
|
| 47 |
|
| 48 |
# Launch the Gradio interface
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
+
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCMultistepScheduler
|
| 4 |
from huggingface_hub import login
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
# Log in to Hugging Face with your token
|
| 8 |
token = os.getenv("HF_TOKEN")
|
| 9 |
login(token=token)
|
| 10 |
|
| 11 |
+
# Model IDs for Stable Diffusion 1.5 and ControlNet
|
| 12 |
+
model_id = "runwayml/stable-diffusion-v1-5" # Compatible with ControlNet
|
| 13 |
+
controlnet_id = "lllyasviel/control_v11p_sd15_inpaint"
|
| 14 |
|
| 15 |
+
# Load the ControlNet model and Stable Diffusion pipeline
|
| 16 |
+
controlnet = ControlNetModel.from_pretrained(controlnet_id, torch_dtype=torch.float16)
|
| 17 |
+
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
| 18 |
+
model_id, controlnet=controlnet, torch_dtype=torch.float16
|
| 19 |
+
)
|
| 20 |
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
| 21 |
pipe = pipe.to("cuda") if torch.cuda.is_available() else pipe
|
| 22 |
|
| 23 |
+
# Define the Gradio interface function
|
| 24 |
def generate_image(prompt, reference_image):
|
| 25 |
+
# Prepare the reference image for ControlNet
|
| 26 |
reference_image = reference_image.convert("RGB").resize((512, 512))
|
| 27 |
|
| 28 |
+
# Generate the image with ControlNet conditioning
|
| 29 |
generated_image = pipe(
|
| 30 |
prompt=prompt,
|
| 31 |
image=reference_image,
|
|
|
|
| 43 |
gr.Image(type="pil", label="Reference Image (Style)")
|
| 44 |
],
|
| 45 |
outputs="image",
|
| 46 |
+
title="Image Generation with Stable Diffusion 1.5 and ControlNet",
|
| 47 |
+
description="Generates an image based on a text prompt and a reference image using Stable Diffusion 1.5 with ControlNet."
|
| 48 |
)
|
| 49 |
|
| 50 |
# Launch the Gradio interface
|