File size: 1,977 Bytes
c2dd1fb
6ebd48b
c2dd1fb
6ebd48b
c2dd1fb
924b685
 
 
 
6ebd48b
883f499
924b685
 
 
 
c2dd1fb
 
 
 
6ebd48b
 
 
c2dd1fb
 
92d2137
 
c2dd1fb
 
 
 
924b685
c2dd1fb
924b685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2dd1fb
924b685
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
50
51
52
53
54
55
import gradio as gr
from diffusers import DiffusionPipeline
from PIL import Image
import torch

device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.float16 if device == "cuda" else torch.float32
variant = "fp16" if device == "cuda" else None

pipe = DiffusionPipeline.from_pretrained(
    "stabilityai/sdxl-turbo",
    torch_dtype=dtype,
    variant=variant
).to(device)

def infer(color_prompt, phone_type_prompt, design_prompt):
    prompt = (
        f"A single vertical {color_prompt} colored {phone_type_prompt} back cover featuring a bold {design_prompt} design on the front, hanging on the plain wall. The soft light and shadows, creating a striking contrast against the minimal background, evoking modern sophistication."
    )
    image = pipe(prompt).images[0]
    message = "Design generated successfully!"
    return image, message

def save_design(image):
    if image is None:
        return "No image to save. Please generate a design first."
    file_path = "saved_design.png"
    image.save(file_path)
    return f"Design saved as {file_path}!"

with gr.Blocks() as interface:
    gr.Markdown("# **AI Phone Cover Designer**")
    with gr.Row():
        with gr.Column(scale=1):
            color_prompt = gr.Textbox(label="Color")
            phone_type_prompt = gr.Textbox(label="Mobile Type")
            design_prompt = gr.Textbox(label="Design Details")
            generate_button = gr.Button("Generate Design")
            save_button = gr.Button("Save Design")
        with gr.Column(scale=1):
            output_image = gr.Image(label="Generated Design")
            output_message = gr.Textbox(label="Status", interactive=False)

    generate_button.click(
        infer,
        inputs=[color_prompt, phone_type_prompt, design_prompt],
        outputs=[output_image, output_message],
    )
    save_button.click(
        save_design,
        inputs=[output_image],
        outputs=output_message,
    )

interface.launch(debug=True)