File size: 1,532 Bytes
5e4062b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218a2c1
5e4062b
 
 
 
 
 
 
 
 
 
218a2c1
 
5e4062b
 
 
 
 
 
 
 
 
 
 
 
218a2c1
5e4062b
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import torch
import gradio as gr
from diffusers import StableDiffusionXLPipeline
from PIL import Image
from io import BytesIO
import os
import requests
import time
from tqdm import tqdm

# Load local Stable Diffusion XL model
model_path = "networks/TShirtDesignRedmondV2-Tshirtdesign-TshirtDesignAF.safetensors"
pipe = StableDiffusionXLPipeline.from_single_file(
    model_path,
    torch_dtype=torch.float16, 
    use_safetensors=True,
)
pipe = pipe.to("cuda")

def infer(color_prompt, dress_type_prompt, design_prompt):
    prompt = (
        f"A single {color_prompt} colored {dress_type_prompt} featuring a bold {design_prompt} design printed on the {dress_type_prompt},"
        " hanging on a plain wall. The soft light and shadows create a striking contrast against the minimal background, evoking modern sophistication."
    )
    
    print("Generating image locally with prompt:", prompt)
    try:
        image = pipe(prompt).images[0]
        return image
    except Exception as e:
        print("Local generation failed.", str(e))
        return None

# Gradio Interface
iface = gr.Interface(
    fn=infer,
    inputs=[
        gr.Textbox(lines=1, placeholder="Color"),
        gr.Textbox(lines=1, placeholder="Dress Type"),
        gr.Textbox(lines=2, placeholder="Design"),
    ],
    outputs="image",
    title="AI-Generated T-Shirt Designs",
    description="Generate custom t-shirt designs using AI!",
    examples=[["Red", "T-shirt", "Minimalistic logo"]]
)

print("Launching Gradio interface...")
iface.launch()