Update app.py
Browse files
app.py
CHANGED
@@ -117,35 +117,39 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
117 |
});
|
118 |
</script>
|
119 |
"""
|
120 |
-
|
121 |
-
# Function to load images dynamically from "New folder (4)"
|
122 |
def load_gallery_images():
|
123 |
folder_path = "New folder (4)"
|
124 |
images_with_captions = []
|
|
|
|
|
125 |
for filename in os.listdir(folder_path):
|
126 |
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.webp')):
|
127 |
-
img_path = os.path.join(folder_path, filename)
|
128 |
-
caption = filename.rsplit('.', 1)[0]
|
129 |
images_with_captions.append((img_path, caption))
|
130 |
return images_with_captions
|
131 |
|
132 |
gallery_images = load_gallery_images()
|
133 |
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
with gr.Blocks(css=custom_css) as interface:
|
136 |
gr.HTML(custom_js)
|
137 |
gr.Markdown("# **AI Phone Cover Designer**")
|
138 |
gr.Markdown("Create custom phone covers with AI. Save your designs for future use.")
|
139 |
|
140 |
-
# Navigation Tabs
|
141 |
with gr.Tabs():
|
142 |
with gr.Tab("Home"):
|
143 |
gr.Markdown("Welcome to the **AI Phone Cover Designer**! Use the 'Design' tab to start creating custom designs.")
|
144 |
gr.Markdown("### Gallery")
|
145 |
-
gallery_html = "<div class='carousel'>"
|
146 |
-
for img_path, caption in gallery_images:
|
147 |
-
gallery_html += f"<div class='image-container'><img src='{img_path}' alt='Design'><div class='caption'>{caption}</div></div>"
|
148 |
-
gallery_html += "</div>"
|
149 |
gr.HTML(gallery_html)
|
150 |
|
151 |
with gr.Tab("Design"):
|
@@ -161,7 +165,6 @@ with gr.Blocks(css=custom_css) as interface:
|
|
161 |
output_image = gr.Image(label="Generated Design")
|
162 |
output_message = gr.Textbox(label="AI Assistant Message", interactive=False)
|
163 |
|
164 |
-
# Button Actions
|
165 |
generate_button.click(
|
166 |
infer,
|
167 |
inputs=[color_prompt, phone_type_prompt, design_prompt],
|
@@ -187,5 +190,4 @@ with gr.Blocks(css=custom_css) as interface:
|
|
187 |
Start designing today and bring your creative ideas to life!
|
188 |
""")
|
189 |
|
190 |
-
# Launch the app
|
191 |
interface.launch(debug=True)
|
|
|
117 |
});
|
118 |
</script>
|
119 |
"""
|
|
|
|
|
120 |
def load_gallery_images():
|
121 |
folder_path = "New folder (4)"
|
122 |
images_with_captions = []
|
123 |
+
if not os.path.exists(folder_path):
|
124 |
+
return images_with_captions
|
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 |
+
caption = filename.rsplit('.', 1)[0]
|
129 |
images_with_captions.append((img_path, caption))
|
130 |
return images_with_captions
|
131 |
|
132 |
gallery_images = load_gallery_images()
|
133 |
|
134 |
+
gallery_html = "<div class='carousel'>"
|
135 |
+
for img_path, caption in gallery_images:
|
136 |
+
gallery_html += (
|
137 |
+
f"<div class='image-container'>"
|
138 |
+
f"<img src='file://{img_path}' alt='Design'>"
|
139 |
+
f"<div class='caption'>{caption}</div>"
|
140 |
+
f"</div>"
|
141 |
+
)
|
142 |
+
gallery_html += "</div>"
|
143 |
+
|
144 |
with gr.Blocks(css=custom_css) as interface:
|
145 |
gr.HTML(custom_js)
|
146 |
gr.Markdown("# **AI Phone Cover Designer**")
|
147 |
gr.Markdown("Create custom phone covers with AI. Save your designs for future use.")
|
148 |
|
|
|
149 |
with gr.Tabs():
|
150 |
with gr.Tab("Home"):
|
151 |
gr.Markdown("Welcome to the **AI Phone Cover Designer**! Use the 'Design' tab to start creating custom designs.")
|
152 |
gr.Markdown("### Gallery")
|
|
|
|
|
|
|
|
|
153 |
gr.HTML(gallery_html)
|
154 |
|
155 |
with gr.Tab("Design"):
|
|
|
165 |
output_image = gr.Image(label="Generated Design")
|
166 |
output_message = gr.Textbox(label="AI Assistant Message", interactive=False)
|
167 |
|
|
|
168 |
generate_button.click(
|
169 |
infer,
|
170 |
inputs=[color_prompt, phone_type_prompt, design_prompt],
|
|
|
190 |
Start designing today and bring your creative ideas to life!
|
191 |
""")
|
192 |
|
|
|
193 |
interface.launch(debug=True)
|