File size: 7,202 Bytes
3519dec
 
587d018
3519dec
 
 
 
 
 
21e44c2
23585ff
3519dec
23585ff
 
3519dec
 
 
 
3397572
3519dec
 
 
3397572
3519dec
23585ff
3519dec
 
 
 
 
 
 
 
6703e90
23585ff
3519dec
 
 
 
 
 
 
 
 
587d018
 
 
6703e90
 
04a6d22
21e44c2
3519dec
 
0f68170
3519dec
 
6703e90
3519dec
6703e90
 
 
 
 
 
 
 
 
 
 
0f68170
6703e90
 
 
 
23585ff
98d0fd4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3519dec
 
85160c5
587d018
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98d0fd4
 
85160c5
 
 
98d0fd4
85160c5
98d0fd4
 
21e44c2
3519dec
587d018
0f68170
6703e90
98d0fd4
6703e90
 
 
587d018
98d0fd4
 
 
 
 
 
 
6703e90
 
 
 
 
 
587d018
6703e90
 
 
 
 
3519dec
6703e90
 
 
 
 
 
 
 
587d018
6703e90
 
 
 
ec81866
6703e90
 
 
 
 
 
 
 
 
 
 
3519dec
587d018
85160c5
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import gradio as gr
import requests
from PIL import Image
from io import BytesIO
from tqdm import tqdm
import time

repo = "artificialguybr/TshirtDesignRedmond-V2"

# Generate design based on prompts
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."
    )
    full_prompt = f"{prompt}"

    print("Generating image with prompt:", full_prompt)
    api_url = f"https://api-inference.huggingface.co/models/{repo}"
    headers = {}
    payload = {
        "inputs": full_prompt,
        "parameters": {
            "negative_prompt": "(worst quality, low quality, lowres, oversaturated, grayscale, bad photo:1.4)",
            "num_inference_steps": 30,
            "scheduler": "DPMSolverMultistepScheduler",
        },
    }

    error_count = 0
    pbar = tqdm(total=None, desc="Loading model")
    while True:
        response = requests.post(api_url, headers=headers, json=payload)
        if response.status_code == 200:
            speech_text = f"Your design is generated with the color '{color_prompt}', mobile type '{phone_type_prompt}', and design '{design_prompt}'."
            return Image.open(BytesIO(response.content)), speech_text
        elif response.status_code == 503:
            time.sleep(1)
            pbar.update(1)
        elif response.status_code == 500 and error_count < 5:
            time.sleep(1)
            error_count += 1
        else:
            raise Exception(f"API Error: {response.status_code}")

# Function to save the design
def save_design(image):
    file_path = "saved_design.png"
    image.save(file_path)
    return f"Design saved as {file_path}!"

# Custom CSS for animations
custom_css = """
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    overflow: hidden;
}
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(-45deg, #ff9a9e, #fad0c4, #fbc2eb, #8fd3f4);
    background-size: 400% 400%;
    z-index: -1;
    animation: gradientShift 15s ease infinite;
}
@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
.carousel {
    display: flex;
    overflow-x: auto;
    scroll-behavior: smooth;
}
.carousel .image-container {
    display: inline-block;
    text-align: center;
    margin: 0 10px;
}
.carousel img {
    max-height: 200px;
    border-radius: 10px;
    transition: transform 0.3s;
}
.carousel img:hover {
    transform: scale(1.1);
}
.carousel .caption {
    margin-top: 5px;
    font-size: 14px;
    color: #333;
}
"""

# JavaScript for text-to-speech
custom_js = """
<script>
document.addEventListener('DOMContentLoaded', function () {
    function speak(text) {
        const synth = window.speechSynthesis;
        const utterance = new SpeechSynthesisUtterance(text);
        synth.speak(utterance);
    }
    document.addEventListener('gradio_event:output_update', (event) => {
        const outputText = event.detail?.text || '';
        if (outputText) {
            speak(outputText);
        }
    });
});
</script>
"""

# Gallery Images with captions
gallery_images = [
    ("https://gaur3009-phone-c.hf.space/gradio_api/file=/tmp/gradio/387f5407e32dd2e2d9e7017977f5ee98e4f40dcb8b1d2a9ef23612255a675163/image.webp", "Red Color, iPhone 14, Naruto Anime Theme"),
    ("https://gaur3009-phone-c.hf.space/gradio_api/file=/tmp/gradio/3037d9cae7a86b29be5969cf3a361ae847915b54d97d6d5dffb6e019a2b9ddc9/image.webp", "Red Color, iPhone 14, Darth Vader Theme"),
    ("https://gaur3009-phone-c.hf.space/gradio_api/file=/tmp/gradio/1958c8d60219357edbb2e1f69331152f1cd1109407b274c4511a810650dd574b/image.webp", "Black, iPhone 15, Thomas Shelby (Peaky Blinders) Theme"),
    ("https://gaur3009-phone-c.hf.space/gradio_api/file=/tmp/gradio/183392add00a7fa3d53653f856bc88d4113bd74c0d37c43de7a9af414e9c1d84/image.webp", "Green color, iPhone, Green Goblin"),
    ("https://gaur3009-phone-c.hf.space/gradio_api/file=/tmp/gradio/b7b0b2415f15f810f71658616a885b97c0466d09f1d852684a868ab9b5d18e6c/image.webp", "White and Cream Color, iPhone 15, Iron-Man"),
]

# Gradio interface
with gr.Blocks(css=custom_css) as interface:
    gr.HTML(custom_js)
    gr.Markdown("# **AI Phone Cover Designer**")
    gr.Markdown("Create custom phone covers with AI. Save your designs for future use.")

    # Navigation Tabs
    with gr.Tabs():
        with gr.Tab("Home"):
            gr.Markdown("Welcome to the **AI Phone Cover Designer**! Use the 'Design' tab to start creating custom designs.")
            gr.Markdown("### Gallery")
            gallery_html = "<div class='carousel'>"
            for img_url, caption in gallery_images:
                gallery_html += f"<div class='image-container'><img src='{img_url}' alt='Design'><div class='caption'>{caption}</div></div>"
            gallery_html += "</div>"
            gr.HTML(gallery_html)

        with gr.Tab("Design"):
            with gr.Row():
                with gr.Column(scale=1):
                    color_prompt = gr.Textbox(label="Color", placeholder="E.g., Red")
                    phone_type_prompt = gr.Textbox(label="Mobile type", placeholder="E.g., iPhone, Samsung")
                    design_prompt = gr.Textbox(label="Design Details", placeholder="E.g., Bold stripes with geometric patterns")
                    chatbot = gr.Chatbot()
                    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="AI Assistant Message", interactive=False)

            # Button Actions
            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,
            )

        with gr.Tab("About"):
            gr.Markdown("""
            ## About AI Phone Cover Maker
            The **AI Phone Cover Maker** is a cutting-edge tool designed to help users create personalized phone cover designs quickly and easily. 
            Powered by AI, it uses advanced image generation techniques to craft unique, high-quality designs for any mobile device.
            
            ### Features:
            - Create custom designs using simple prompts.
            - Generate designs for various phone models.
            - Save your designs for future use.
            
            Start designing today and bring your creative ideas to life!
            """)

# Launch the app
interface.launch(debug=True)