MaxMilan1
commited on
Commit
·
f1759ae
1
Parent(s):
0fc6bc9
changes
Browse files
app.py
CHANGED
@@ -1,33 +1,23 @@
|
|
1 |
import spaces
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
-
from diffusers import
|
5 |
-
from huggingface_hub import hf_hub_download
|
6 |
-
from safetensors.torch import load_file
|
7 |
import rembg
|
8 |
-
from io import BytesIO
|
9 |
-
import PIL.Image as Image
|
10 |
-
import cv2
|
11 |
-
import numpy
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
ckpt = "sdxl_lightning_4step_unet.safetensors"
|
16 |
|
17 |
-
unet =
|
18 |
-
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
|
19 |
-
pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
|
20 |
-
|
21 |
-
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
|
22 |
|
23 |
# Function to generate an image from text using diffusion
|
24 |
@spaces.GPU
|
25 |
def generate_image(prompt):
|
26 |
prompt += "no background, side view, minimalist shot"
|
27 |
|
28 |
-
image = pipe(prompt
|
|
|
29 |
|
30 |
-
return image
|
31 |
|
32 |
_TITLE = "Shoe Generator"
|
33 |
with gr.Blocks(_TITLE) as ShoeGen:
|
@@ -37,8 +27,9 @@ with gr.Blocks(_TITLE) as ShoeGen:
|
|
37 |
# neg_prompt = gr.Textbox(label="Enter a negative prompt", value="low quality, watermark, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, body out of frame, blurry, bad anatomy, blurred, watermark, grainy, signature, cut off, draft, closed eyes, text, logo")
|
38 |
button_gen = gr.Button("Generate Image")
|
39 |
with gr.Column():
|
40 |
-
image = gr.Image(label="Generated Image", show_download_button=True)
|
|
|
41 |
|
42 |
-
button_gen.click(generate_image, inputs=[prompt], outputs=[image])
|
43 |
|
44 |
ShoeGen.launch()
|
|
|
1 |
import spaces
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
+
from diffusers import DiffusionPipeline
|
|
|
|
|
5 |
import rembg
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
8 |
+
pipe.to("cuda")
|
|
|
9 |
|
10 |
+
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# Function to generate an image from text using diffusion
|
13 |
@spaces.GPU
|
14 |
def generate_image(prompt):
|
15 |
prompt += "no background, side view, minimalist shot"
|
16 |
|
17 |
+
image = pipe(prompt).images[0]
|
18 |
+
image2 = rembg.remove(image)
|
19 |
|
20 |
+
return image, image2
|
21 |
|
22 |
_TITLE = "Shoe Generator"
|
23 |
with gr.Blocks(_TITLE) as ShoeGen:
|
|
|
27 |
# neg_prompt = gr.Textbox(label="Enter a negative prompt", value="low quality, watermark, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, body out of frame, blurry, bad anatomy, blurred, watermark, grainy, signature, cut off, draft, closed eyes, text, logo")
|
28 |
button_gen = gr.Button("Generate Image")
|
29 |
with gr.Column():
|
30 |
+
image = gr.Image(label="Generated Image", show_download_button=True)
|
31 |
+
image_nobg = gr.Image(label="Generated Image (No Background)", show_download_button=True)
|
32 |
|
33 |
+
button_gen.click(generate_image, inputs=[prompt], outputs=[image, image_nobg])
|
34 |
|
35 |
ShoeGen.launch()
|