Spaces:
Runtime error
Runtime error
Update app.py
#1
by
fragger246
- opened
app.py
CHANGED
@@ -1,46 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
import random
|
4 |
-
from diffusers import DiffusionPipeline
|
5 |
-
import torch
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
pipe.enable_xformers_memory_efficient_attention()
|
13 |
-
pipe = pipe.to(device)
|
14 |
-
else:
|
15 |
-
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
|
16 |
-
pipe = pipe.to(device)
|
17 |
-
|
18 |
-
MAX_SEED = np.iinfo(np.int32).max
|
19 |
-
MAX_IMAGE_SIZE = 1024
|
20 |
-
|
21 |
-
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
22 |
-
|
23 |
-
if randomize_seed:
|
24 |
-
seed = random.randint(0, MAX_SEED)
|
25 |
-
|
26 |
-
generator = torch.Generator().manual_seed(seed)
|
27 |
-
|
28 |
-
image = pipe(
|
29 |
-
prompt = prompt,
|
30 |
-
negative_prompt = negative_prompt,
|
31 |
-
guidance_scale = guidance_scale,
|
32 |
-
num_inference_steps = num_inference_steps,
|
33 |
-
width = width,
|
34 |
-
height = height,
|
35 |
-
generator = generator
|
36 |
-
).images[0]
|
37 |
-
|
38 |
-
return image
|
39 |
|
40 |
examples = [
|
41 |
-
"
|
42 |
-
"
|
43 |
-
"
|
44 |
]
|
45 |
|
46 |
css="""
|
@@ -50,97 +20,55 @@ css="""
|
|
50 |
}
|
51 |
"""
|
52 |
|
53 |
-
if torch.cuda.is_available():
|
54 |
-
power_device = "GPU"
|
55 |
-
else:
|
56 |
-
power_device = "CPU"
|
57 |
-
|
58 |
with gr.Blocks(css=css) as demo:
|
59 |
|
60 |
with gr.Column(elem_id="col-container"):
|
61 |
gr.Markdown(f"""
|
62 |
-
#
|
63 |
-
Currently running on {power_device}.
|
64 |
""")
|
65 |
|
66 |
with gr.Row():
|
67 |
|
68 |
-
|
69 |
-
label="
|
70 |
-
|
71 |
-
|
72 |
-
placeholder="Enter your prompt",
|
73 |
container=False,
|
74 |
)
|
75 |
|
76 |
-
run_button = gr.Button("
|
77 |
|
78 |
-
result = gr.
|
79 |
|
80 |
-
with gr.Accordion("
|
81 |
|
82 |
-
|
83 |
-
label="
|
84 |
-
|
85 |
-
|
86 |
-
visible=False,
|
87 |
)
|
88 |
|
89 |
-
|
90 |
-
label="
|
91 |
-
|
92 |
-
|
93 |
-
step=1,
|
94 |
-
value=0,
|
95 |
)
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
label="Width",
|
103 |
-
minimum=256,
|
104 |
-
maximum=MAX_IMAGE_SIZE,
|
105 |
-
step=32,
|
106 |
-
value=512,
|
107 |
-
)
|
108 |
-
|
109 |
-
height = gr.Slider(
|
110 |
-
label="Height",
|
111 |
-
minimum=256,
|
112 |
-
maximum=MAX_IMAGE_SIZE,
|
113 |
-
step=32,
|
114 |
-
value=512,
|
115 |
-
)
|
116 |
|
117 |
-
with gr.Row():
|
118 |
-
|
119 |
-
guidance_scale = gr.Slider(
|
120 |
-
label="Guidance scale",
|
121 |
-
minimum=0.0,
|
122 |
-
maximum=10.0,
|
123 |
-
step=0.1,
|
124 |
-
value=0.0,
|
125 |
-
)
|
126 |
-
|
127 |
-
num_inference_steps = gr.Slider(
|
128 |
-
label="Number of inference steps",
|
129 |
-
minimum=1,
|
130 |
-
maximum=12,
|
131 |
-
step=1,
|
132 |
-
value=2,
|
133 |
-
)
|
134 |
-
|
135 |
gr.Examples(
|
136 |
-
examples
|
137 |
-
inputs
|
138 |
)
|
139 |
|
140 |
run_button.click(
|
141 |
-
fn
|
142 |
-
inputs
|
143 |
-
outputs
|
144 |
)
|
145 |
|
146 |
-
demo.queue().launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import random
|
|
|
|
|
3 |
|
4 |
+
# Example T-shirt mockup generation function (replace with actual implementation)
|
5 |
+
def generate_tshirt_mockup(style, color, graphics, text=None):
|
6 |
+
# Generate a mockup based on T-shirt style, color, graphics, and optionally text
|
7 |
+
mockup = f"Generated T-shirt mockup:\nStyle: {style}\nColor: {color}\nGraphics: {graphics}\nText: {text}" if text else f"Generated T-shirt mockup:\nStyle: {style}\nColor: {color}\nGraphics: {graphics}"
|
8 |
+
return mockup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
examples = [
|
11 |
+
"Casual T-shirt, Blue, with abstract art",
|
12 |
+
"Formal T-shirt, White, with logo",
|
13 |
+
"Sports T-shirt, Red, with team name",
|
14 |
]
|
15 |
|
16 |
css="""
|
|
|
20 |
}
|
21 |
"""
|
22 |
|
|
|
|
|
|
|
|
|
|
|
23 |
with gr.Blocks(css=css) as demo:
|
24 |
|
25 |
with gr.Column(elem_id="col-container"):
|
26 |
gr.Markdown(f"""
|
27 |
+
# T-shirt Mockup Generator
|
|
|
28 |
""")
|
29 |
|
30 |
with gr.Row():
|
31 |
|
32 |
+
style = gr.Dropdown(
|
33 |
+
label="T-shirt Style",
|
34 |
+
choices=["Casual", "Formal", "Sports"],
|
35 |
+
default="Casual",
|
|
|
36 |
container=False,
|
37 |
)
|
38 |
|
39 |
+
run_button = gr.Button("Generate Mockup", scale=0)
|
40 |
|
41 |
+
result = gr.Textbox(label="Mockup", placeholder="Generated Mockup", readonly=True)
|
42 |
|
43 |
+
with gr.Accordion("Design Options", open=False):
|
44 |
|
45 |
+
color = gr.Textbox(
|
46 |
+
label="T-shirt Color",
|
47 |
+
placeholder="Enter color",
|
48 |
+
visible=True,
|
|
|
49 |
)
|
50 |
|
51 |
+
graphics = gr.Textbox(
|
52 |
+
label="Graphics",
|
53 |
+
placeholder="Enter graphic details",
|
54 |
+
visible=True,
|
|
|
|
|
55 |
)
|
56 |
|
57 |
+
text = gr.Textbox(
|
58 |
+
label="Text (optional)",
|
59 |
+
placeholder="Enter text for T-shirt",
|
60 |
+
visible=True,
|
61 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
gr.Examples(
|
64 |
+
examples=examples,
|
65 |
+
inputs=[style]
|
66 |
)
|
67 |
|
68 |
run_button.click(
|
69 |
+
fn=generate_tshirt_mockup,
|
70 |
+
inputs=[style, color, graphics, text],
|
71 |
+
outputs=[result]
|
72 |
)
|
73 |
|
74 |
+
demo.queue().launch()
|