Update app.py
Browse files
app.py
CHANGED
@@ -49,144 +49,101 @@ def save_design(image):
|
|
49 |
image.save(file_path)
|
50 |
return f"Design saved as {file_path}!"
|
51 |
|
52 |
-
#
|
53 |
custom_css = """
|
54 |
body {
|
55 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
56 |
margin: 0;
|
57 |
padding: 0;
|
58 |
overflow: hidden;
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
background-size: 400% 400%;
|
|
|
61 |
animation: gradientShift 15s ease infinite;
|
62 |
}
|
63 |
-
|
64 |
@keyframes gradientShift {
|
65 |
0% { background-position: 0% 50%; }
|
66 |
50% { background-position: 100% 50%; }
|
67 |
100% { background-position: 0% 50%; }
|
68 |
}
|
69 |
-
|
70 |
-
h1, h2, h3 {
|
71 |
-
animation: fadeIn 1s ease-in-out;
|
72 |
-
}
|
73 |
-
|
74 |
-
h1:hover, h2:hover, h3:hover {
|
75 |
-
color: #fbc2eb;
|
76 |
-
transform: scale(1.05);
|
77 |
-
transition: transform 0.3s, color 0.3s;
|
78 |
-
}
|
79 |
-
|
80 |
.carousel {
|
81 |
display: flex;
|
82 |
overflow-x: auto;
|
83 |
scroll-behavior: smooth;
|
84 |
}
|
85 |
-
|
86 |
.carousel .image-container {
|
87 |
display: inline-block;
|
88 |
text-align: center;
|
89 |
margin: 0 10px;
|
90 |
}
|
91 |
-
|
92 |
.carousel img {
|
93 |
max-height: 200px;
|
94 |
border-radius: 10px;
|
95 |
-
transition: transform 0.3s
|
96 |
}
|
97 |
-
|
98 |
.carousel img:hover {
|
99 |
transform: scale(1.1);
|
100 |
-
box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.2);
|
101 |
}
|
102 |
-
|
103 |
.carousel .caption {
|
104 |
margin-top: 5px;
|
105 |
font-size: 14px;
|
106 |
color: #333;
|
107 |
}
|
|
|
108 |
|
109 |
-
#
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
#gallery-container img {
|
118 |
-
width: 200px;
|
119 |
-
height: auto;
|
120 |
-
border-radius: 10px;
|
121 |
-
margin: 10px;
|
122 |
-
transition: transform 0.3s, box-shadow 0.3s;
|
123 |
-
}
|
124 |
-
|
125 |
-
#gallery-container img:hover {
|
126 |
-
transform: scale(1.05);
|
127 |
-
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
128 |
-
}
|
129 |
-
|
130 |
-
h1 {
|
131 |
-
font-size: 3em;
|
132 |
-
text-align: center;
|
133 |
-
color: #fff;
|
134 |
-
margin-top: 50px;
|
135 |
-
}
|
136 |
-
|
137 |
-
h2 {
|
138 |
-
font-size: 2em;
|
139 |
-
text-align: center;
|
140 |
-
color: #fff;
|
141 |
-
margin-top: 20px;
|
142 |
-
}
|
143 |
-
|
144 |
-
h3 {
|
145 |
-
font-size: 1.2em;
|
146 |
-
text-align: center;
|
147 |
-
color: #fff;
|
148 |
-
}
|
149 |
-
|
150 |
-
@media (max-width: 768px) {
|
151 |
-
h1 {
|
152 |
-
font-size: 2em;
|
153 |
-
}
|
154 |
-
h2 {
|
155 |
-
font-size: 1.5em;
|
156 |
-
}
|
157 |
-
h3 {
|
158 |
-
font-size: 1em;
|
159 |
-
}
|
160 |
-
|
161 |
-
#gallery-container {
|
162 |
-
flex-direction: column;
|
163 |
-
align-items: center;
|
164 |
}
|
165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
|
168 |
-
# Update the gallery layout and add responsive behavior
|
169 |
with gr.Blocks(css=custom_css) as interface:
|
170 |
gr.HTML(custom_js)
|
171 |
gr.Markdown("# **AI Phone Cover Designer**")
|
172 |
gr.Markdown("Create custom phone covers with AI. Save your designs for future use.")
|
173 |
-
|
174 |
with gr.Tabs():
|
175 |
with gr.Tab("Home"):
|
176 |
gr.Markdown("Welcome to the **AI Phone Cover Designer**! Use the 'Design' tab to start creating custom designs.")
|
177 |
-
|
178 |
-
# Add animation and more visual elements
|
179 |
-
gr.Markdown("### Gallery of Designs")
|
180 |
if gallery_images:
|
181 |
-
|
182 |
-
gr.Gallery(value=gallery_images, label="Design Gallery", columns=2, height="auto").style(width="100%", height="auto")
|
183 |
else:
|
184 |
gr.Markdown("No images found in the gallery folder.")
|
185 |
-
|
186 |
-
gr.Markdown("""
|
187 |
-
## Get Inspired!
|
188 |
-
Browse through our design gallery to see what others have created, and get inspiration for your next custom phone cover!
|
189 |
-
""")
|
190 |
|
191 |
with gr.Tab("Design"):
|
192 |
with gr.Row():
|
@@ -213,7 +170,7 @@ with gr.Blocks(css=custom_css) as interface:
|
|
213 |
)
|
214 |
|
215 |
with gr.Tab("About"):
|
216 |
-
gr.Markdown("""
|
217 |
## About AI Phone Cover Maker
|
218 |
The **AI Phone Cover Maker** is a cutting-edge tool designed to help users create personalized phone cover designs quickly and easily.
|
219 |
Powered by AI, it uses advanced image generation techniques to craft unique, high-quality designs for any mobile device.
|
@@ -226,4 +183,4 @@ with gr.Blocks(css=custom_css) as interface:
|
|
226 |
Start designing today and bring your creative ideas to life!
|
227 |
""")
|
228 |
|
229 |
-
interface.launch(debug=True)
|
|
|
49 |
image.save(file_path)
|
50 |
return f"Design saved as {file_path}!"
|
51 |
|
52 |
+
# Custom CSS for animations
|
53 |
custom_css = """
|
54 |
body {
|
55 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
56 |
margin: 0;
|
57 |
padding: 0;
|
58 |
overflow: hidden;
|
59 |
+
}
|
60 |
+
body::before {
|
61 |
+
content: "";
|
62 |
+
position: fixed;
|
63 |
+
top: 0;
|
64 |
+
left: 0;
|
65 |
+
width: 100%;
|
66 |
+
height: 100%;
|
67 |
+
background: linear-gradient(-45deg, #ff9a9e, #fad0c4, #fbc2eb, #8fd3f4);
|
68 |
background-size: 400% 400%;
|
69 |
+
z-index: -1;
|
70 |
animation: gradientShift 15s ease infinite;
|
71 |
}
|
|
|
72 |
@keyframes gradientShift {
|
73 |
0% { background-position: 0% 50%; }
|
74 |
50% { background-position: 100% 50%; }
|
75 |
100% { background-position: 0% 50%; }
|
76 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
.carousel {
|
78 |
display: flex;
|
79 |
overflow-x: auto;
|
80 |
scroll-behavior: smooth;
|
81 |
}
|
|
|
82 |
.carousel .image-container {
|
83 |
display: inline-block;
|
84 |
text-align: center;
|
85 |
margin: 0 10px;
|
86 |
}
|
|
|
87 |
.carousel img {
|
88 |
max-height: 200px;
|
89 |
border-radius: 10px;
|
90 |
+
transition: transform 0.3s;
|
91 |
}
|
|
|
92 |
.carousel img:hover {
|
93 |
transform: scale(1.1);
|
|
|
94 |
}
|
|
|
95 |
.carousel .caption {
|
96 |
margin-top: 5px;
|
97 |
font-size: 14px;
|
98 |
color: #333;
|
99 |
}
|
100 |
+
"""
|
101 |
|
102 |
+
# JavaScript for text-to-speech
|
103 |
+
custom_js = """
|
104 |
+
<script>
|
105 |
+
document.addEventListener('DOMContentLoaded', function () {
|
106 |
+
function speak(text) {
|
107 |
+
const synth = window.speechSynthesis;
|
108 |
+
const utterance = new SpeechSynthesisUtterance(text);
|
109 |
+
synth.speak(utterance);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
}
|
111 |
+
document.addEventListener('gradio_event:output_update', (event) => {
|
112 |
+
const outputText = event.detail?.text || '';
|
113 |
+
if (outputText) {
|
114 |
+
speak(outputText);
|
115 |
+
}
|
116 |
+
});
|
117 |
+
});
|
118 |
+
</script>
|
119 |
"""
|
120 |
+
def load_gallery_images():
|
121 |
+
folder_path = "New folder (4)" # Ensure this path is correct
|
122 |
+
images = []
|
123 |
+
if not os.path.exists(folder_path):
|
124 |
+
return images
|
125 |
+
for filename in os.listdir(folder_path):
|
126 |
+
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.webp')):
|
127 |
+
img_path = os.path.abspath(os.path.join(folder_path, filename))
|
128 |
+
images.append(img_path) # Append only the file paths
|
129 |
+
return images
|
130 |
+
|
131 |
+
gallery_images = load_gallery_images()
|
132 |
|
|
|
133 |
with gr.Blocks(css=custom_css) as interface:
|
134 |
gr.HTML(custom_js)
|
135 |
gr.Markdown("# **AI Phone Cover Designer**")
|
136 |
gr.Markdown("Create custom phone covers with AI. Save your designs for future use.")
|
137 |
+
|
138 |
with gr.Tabs():
|
139 |
with gr.Tab("Home"):
|
140 |
gr.Markdown("Welcome to the **AI Phone Cover Designer**! Use the 'Design' tab to start creating custom designs.")
|
141 |
+
gr.Markdown("### Gallery")
|
|
|
|
|
142 |
if gallery_images:
|
143 |
+
gr.Gallery(value=gallery_images, label="Design Gallery", columns=2, height="auto")
|
|
|
144 |
else:
|
145 |
gr.Markdown("No images found in the gallery folder.")
|
146 |
+
|
|
|
|
|
|
|
|
|
147 |
|
148 |
with gr.Tab("Design"):
|
149 |
with gr.Row():
|
|
|
170 |
)
|
171 |
|
172 |
with gr.Tab("About"):
|
173 |
+
gr.Markdown("""
|
174 |
## About AI Phone Cover Maker
|
175 |
The **AI Phone Cover Maker** is a cutting-edge tool designed to help users create personalized phone cover designs quickly and easily.
|
176 |
Powered by AI, it uses advanced image generation techniques to craft unique, high-quality designs for any mobile device.
|
|
|
183 |
Start designing today and bring your creative ideas to life!
|
184 |
""")
|
185 |
|
186 |
+
interface.launch(debug=True)
|