Spaces:
Paused
Paused
test gradio
Browse files- app.py +8 -6
- app_image_style.py +54 -0
app.py
CHANGED
@@ -2,14 +2,10 @@ import gradio as gr
|
|
2 |
from huggingface_hub import login
|
3 |
import os
|
4 |
import spaces
|
5 |
-
import torch
|
6 |
-
from diffusers import StableDiffusionXLPipeline
|
7 |
-
from PIL import Image
|
8 |
-
import torch
|
9 |
-
from diffusers import AutoPipelineForText2Image, DDIMScheduler
|
10 |
from diffusers import AutoPipelineForText2Image
|
11 |
from diffusers.utils import load_image
|
12 |
import torch
|
|
|
13 |
|
14 |
token = os.getenv("HF_TOKEN")
|
15 |
login(token=token)
|
@@ -22,7 +18,13 @@ pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name=
|
|
22 |
|
23 |
@spaces.GPU
|
24 |
def generate_image(prompt, reference_image, controlnet_conditioning_scale):
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
pipeline.set_ip_adapter_scale(controlnet_conditioning_scale)
|
28 |
|
|
|
2 |
from huggingface_hub import login
|
3 |
import os
|
4 |
import spaces
|
|
|
|
|
|
|
|
|
|
|
5 |
from diffusers import AutoPipelineForText2Image
|
6 |
from diffusers.utils import load_image
|
7 |
import torch
|
8 |
+
import tempfile
|
9 |
|
10 |
token = os.getenv("HF_TOKEN")
|
11 |
login(token=token)
|
|
|
18 |
|
19 |
@spaces.GPU
|
20 |
def generate_image(prompt, reference_image, controlnet_conditioning_scale):
|
21 |
+
style_image_paths = []
|
22 |
+
for f in reference_image:
|
23 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") # Adjust suffix if using another format
|
24 |
+
temp_file.write(f.read())
|
25 |
+
temp_file.close()
|
26 |
+
style_image_paths.append(temp_file.name)
|
27 |
+
style_images = [load_image(path) for path in style_image_paths]
|
28 |
|
29 |
pipeline.set_ip_adapter_scale(controlnet_conditioning_scale)
|
30 |
|
app_image_style.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import login
|
3 |
+
import os
|
4 |
+
import spaces
|
5 |
+
import torch
|
6 |
+
from diffusers import StableDiffusionXLPipeline
|
7 |
+
from PIL import Image
|
8 |
+
import torch
|
9 |
+
from diffusers import AutoPipelineForText2Image, DDIMScheduler
|
10 |
+
from diffusers import AutoPipelineForText2Image
|
11 |
+
from diffusers.utils import load_image
|
12 |
+
import torch
|
13 |
+
|
14 |
+
token = os.getenv("HF_TOKEN")
|
15 |
+
login(token=token)
|
16 |
+
|
17 |
+
|
18 |
+
pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16).to("cuda")
|
19 |
+
pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
@spaces.GPU
|
24 |
+
def generate_image(prompt, reference_image, controlnet_conditioning_scale):
|
25 |
+
style_images = [load_image(f.file.name) for f in reference_image]
|
26 |
+
|
27 |
+
pipeline.set_ip_adapter_scale(controlnet_conditioning_scale)
|
28 |
+
|
29 |
+
image = pipeline(
|
30 |
+
prompt=prompt,
|
31 |
+
ip_adapter_image=[style_images],
|
32 |
+
negative_prompt="",
|
33 |
+
guidance_scale=5,
|
34 |
+
num_inference_steps=30,
|
35 |
+
).images[0]
|
36 |
+
|
37 |
+
return image
|
38 |
+
|
39 |
+
# Set up Gradio interface
|
40 |
+
interface = gr.Interface(
|
41 |
+
fn=generate_image,
|
42 |
+
inputs=[
|
43 |
+
gr.Textbox(label="Prompt"),
|
44 |
+
# gr.Image( type= "filepath",label="Reference Image (Style)"),
|
45 |
+
gr.File(file_count="multiple",label="Reference Image (Style)"),
|
46 |
+
gr.Slider(label="Control Net Conditioning Scale", minimum=0, maximum=1.0, step=0.1, value=1.0),
|
47 |
+
],
|
48 |
+
outputs="image",
|
49 |
+
title="Image Generation with Stable Diffusion 3 medium and ControlNet",
|
50 |
+
description="Generates an image based on a text prompt and a reference image using Stable Diffusion 3 medium with ControlNet."
|
51 |
+
|
52 |
+
)
|
53 |
+
|
54 |
+
interface.launch()
|