MaxMilan1
commited on
Commit
·
af84433
1
Parent(s):
0bbe8f6
CHANGES
Browse files- app.py +15 -15
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,34 +1,34 @@
|
|
1 |
import spaces
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
-
from diffusers import
|
|
|
|
|
5 |
import rembg
|
6 |
from io import BytesIO
|
7 |
import PIL.Image as Image
|
8 |
import cv2
|
9 |
import numpy
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
vae=vae,
|
15 |
-
torch_dtype=torch.float16,
|
16 |
-
use_safetensors=True,
|
17 |
-
variant="fp16")
|
18 |
|
19 |
-
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# Function to generate an image from text using diffusion
|
22 |
@spaces.GPU
|
23 |
def generate_image(prompt, neg_prompt):
|
24 |
prompt += "no background, side view, minimalist shot"
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
opencvImage = cv2.cvtColor(numpy.array(pil_image), cv2.COLOR_RGB2BGR)
|
29 |
|
30 |
-
|
31 |
-
return pil_image, cv2_image
|
32 |
|
33 |
_TITLE = "Shoe Generator"
|
34 |
with gr.Blocks(_TITLE) as ShoeGen:
|
|
|
1 |
import spaces
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
+
from diffusers import UNet2DConditionModel, StableDiffusionXLPipeline, EulerDiscreteScheduler
|
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 |
+
base = "stabilityai/stable-diffusion-xl-base-1.0"
|
14 |
+
repo = "ByteDance/SDXL-Lightning"
|
15 |
+
ckpt = "sdxl_lightning_4step_unet.safetensors"
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
|
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, neg_prompt):
|
26 |
prompt += "no background, side view, minimalist shot"
|
27 |
+
|
28 |
+
image = pipe(prompt, num_inference_steps=4, guidance_scale=0).images[0]
|
29 |
+
image2 = rembg.remove(image)
|
|
|
30 |
|
31 |
+
return image, image2
|
|
|
32 |
|
33 |
_TITLE = "Shoe Generator"
|
34 |
with gr.Blocks(_TITLE) as ShoeGen:
|
requirements.txt
CHANGED
@@ -8,4 +8,5 @@ rembg
|
|
8 |
Pillow
|
9 |
Python-IO
|
10 |
numpy
|
11 |
-
opencv-python
|
|
|
|
8 |
Pillow
|
9 |
Python-IO
|
10 |
numpy
|
11 |
+
opencv-python
|
12 |
+
huggingface-hub
|