Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,37 @@
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image, ImageDraw, ImageFilter
|
3 |
-
import requests
|
4 |
-
from io import BytesIO
|
5 |
import torch
|
|
|
6 |
import torchvision.transforms as T
|
7 |
from torchvision import models
|
8 |
import numpy as np
|
9 |
import cv2
|
10 |
|
11 |
-
#
|
12 |
-
|
|
|
|
|
|
|
13 |
|
|
|
|
|
|
|
|
|
|
|
14 |
def generate_cloth(color_prompt):
|
15 |
-
prompt = f"A plain {color_prompt}
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
if response.status_code == 200:
|
21 |
-
return Image.open(BytesIO(response.content)).convert("RGB")
|
22 |
-
else:
|
23 |
-
raise Exception(f"Error generating cloth: {response.status_code}")
|
24 |
|
|
|
25 |
def generate_design(design_prompt):
|
26 |
prompt = f"A bold {design_prompt} design with vibrant colors, highly detailed."
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
if response.status_code == 200:
|
32 |
-
return Image.open(BytesIO(response.content)).convert("RGBA")
|
33 |
-
else:
|
34 |
-
raise Exception(f"Error generating design: {response.status_code}")
|
35 |
|
36 |
# Load pretrained DeepLabV3 model for T-shirt segmentation
|
37 |
segmentation_model = models.segmentation.deeplabv3_resnet101(pretrained=True).eval()
|
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image, ImageDraw, ImageFilter
|
|
|
|
|
3 |
import torch
|
4 |
+
from diffusers import StableDiffusionXLImg2ImgPipeline, StableDiffusionXLInpaintPipeline
|
5 |
import torchvision.transforms as T
|
6 |
from torchvision import models
|
7 |
import numpy as np
|
8 |
import cv2
|
9 |
|
10 |
+
# Load the SDXL pipelines
|
11 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
+
pipe_tshirt = StableDiffusionXLImg2ImgPipeline.from_pretrained(
|
13 |
+
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
|
14 |
+
).to(device)
|
15 |
|
16 |
+
pipe_design = StableDiffusionXLImg2ImgPipeline.from_pretrained(
|
17 |
+
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
|
18 |
+
).to(device)
|
19 |
+
|
20 |
+
# Generate T-shirt image
|
21 |
def generate_cloth(color_prompt):
|
22 |
+
prompt = f"A plain {color_prompt} T-shirt hanging on a plain wall, realistic, high-quality photo."
|
23 |
+
image = pipe_tshirt(
|
24 |
+
prompt=prompt, strength=0.8, guidance_scale=7.5, num_inference_steps=30
|
25 |
+
).images[0]
|
26 |
+
return image
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
# Generate design image
|
29 |
def generate_design(design_prompt):
|
30 |
prompt = f"A bold {design_prompt} design with vibrant colors, highly detailed."
|
31 |
+
image = pipe_design(
|
32 |
+
prompt=prompt, strength=0.8, guidance_scale=7.5, num_inference_steps=30
|
33 |
+
).images[0]
|
34 |
+
return image.convert("RGBA")
|
|
|
|
|
|
|
|
|
35 |
|
36 |
# Load pretrained DeepLabV3 model for T-shirt segmentation
|
37 |
segmentation_model = models.segmentation.deeplabv3_resnet101(pretrained=True).eval()
|