Update app.py
Browse files
app.py
CHANGED
@@ -48,6 +48,16 @@ def save_design(image):
|
|
48 |
image.save(file_path)
|
49 |
return f"Design saved as {file_path}!"
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
# Custom CSS for animations
|
52 |
custom_css = """
|
53 |
body {
|
@@ -75,46 +85,28 @@ body::before {
|
|
75 |
}
|
76 |
"""
|
77 |
|
78 |
-
# JavaScript for text-to-speech and particles
|
79 |
-
custom_js = """
|
80 |
-
<script>
|
81 |
-
document.addEventListener('DOMContentLoaded', function () {
|
82 |
-
// Add particles
|
83 |
-
const particlesContainer = document.createElement('div');
|
84 |
-
particlesContainer.classList.add('particles');
|
85 |
-
for (let i = 0; i < 5; i++) {
|
86 |
-
const particle = document.createElement('div');
|
87 |
-
particle.classList.add('particle');
|
88 |
-
particlesContainer.appendChild(particle);
|
89 |
-
}
|
90 |
-
document.body.appendChild(particlesContainer);
|
91 |
-
|
92 |
-
// Text-to-speech functionality
|
93 |
-
function speak(text) {
|
94 |
-
const synth = window.speechSynthesis;
|
95 |
-
const utterance = new SpeechSynthesisUtterance(text);
|
96 |
-
synth.speak(utterance);
|
97 |
-
}
|
98 |
-
document.addEventListener('gradio_event:output_update', (event) => {
|
99 |
-
const outputText = event.detail?.text || '';
|
100 |
-
if (outputText) {
|
101 |
-
speak(outputText);
|
102 |
-
}
|
103 |
-
});
|
104 |
-
});
|
105 |
-
</script>
|
106 |
-
"""
|
107 |
-
|
108 |
# Gradio interface
|
109 |
with gr.Blocks(css=custom_css) as interface:
|
110 |
-
gr.HTML(custom_js)
|
111 |
gr.Markdown("# **AI Phone Cover Designer**")
|
112 |
gr.Markdown("Create custom phone covers with AI. Save your designs for future use.")
|
113 |
|
114 |
# Navigation Tabs
|
115 |
with gr.Tabs():
|
116 |
with gr.Tab("Home"):
|
117 |
-
gr.Markdown("Welcome to the **AI Phone Cover Designer**!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
with gr.Tab("Design"):
|
120 |
with gr.Row():
|
@@ -122,7 +114,6 @@ with gr.Blocks(css=custom_css) as interface:
|
|
122 |
color_prompt = gr.Textbox(label="Color", placeholder="E.g., Red")
|
123 |
phone_type_prompt = gr.Textbox(label="Mobile type", placeholder="E.g., iPhone, Samsung")
|
124 |
design_prompt = gr.Textbox(label="Design Details", placeholder="E.g., Bold stripes with geometric patterns")
|
125 |
-
chatbot = gr.Chatbot()
|
126 |
generate_button = gr.Button("Generate Design")
|
127 |
save_button = gr.Button("Save Design")
|
128 |
with gr.Column(scale=1):
|
@@ -155,5 +146,4 @@ with gr.Blocks(css=custom_css) as interface:
|
|
155 |
Start designing today and bring your creative ideas to life!
|
156 |
""")
|
157 |
|
158 |
-
# Launch the app
|
159 |
interface.launch(debug=True)
|
|
|
48 |
image.save(file_path)
|
49 |
return f"Design saved as {file_path}!"
|
50 |
|
51 |
+
# Function to fetch saved designs for carousel
|
52 |
+
def fetch_saved_designs_with_captions():
|
53 |
+
# Replace with your own logic to fetch saved images and captions
|
54 |
+
designs = [
|
55 |
+
("saved_design_1.png", "Bold Red Geometric Design"),
|
56 |
+
("saved_design_2.png", "Blue Abstract Art"),
|
57 |
+
("saved_design_3.png", "Green Floral Pattern"),
|
58 |
+
]
|
59 |
+
return [{"image": img, "caption": cap} for img, cap in designs]
|
60 |
+
|
61 |
# Custom CSS for animations
|
62 |
custom_css = """
|
63 |
body {
|
|
|
85 |
}
|
86 |
"""
|
87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
# Gradio interface
|
89 |
with gr.Blocks(css=custom_css) as interface:
|
|
|
90 |
gr.Markdown("# **AI Phone Cover Designer**")
|
91 |
gr.Markdown("Create custom phone covers with AI. Save your designs for future use.")
|
92 |
|
93 |
# Navigation Tabs
|
94 |
with gr.Tabs():
|
95 |
with gr.Tab("Home"):
|
96 |
+
gr.Markdown("### Welcome to the **AI Phone Cover Designer**!")
|
97 |
+
gr.Markdown("Below is a carousel showcasing some of the saved designs.")
|
98 |
+
|
99 |
+
# Carousel to display saved designs
|
100 |
+
design_carousel = gr.Carousel(
|
101 |
+
items=fetch_saved_designs_with_captions(),
|
102 |
+
item_width=300,
|
103 |
+
item_height=400,
|
104 |
+
item_spacing=10,
|
105 |
+
loop=True,
|
106 |
+
autoplay=True,
|
107 |
+
autoplay_interval=3000,
|
108 |
+
label="Saved Designs Carousel",
|
109 |
+
)
|
110 |
|
111 |
with gr.Tab("Design"):
|
112 |
with gr.Row():
|
|
|
114 |
color_prompt = gr.Textbox(label="Color", placeholder="E.g., Red")
|
115 |
phone_type_prompt = gr.Textbox(label="Mobile type", placeholder="E.g., iPhone, Samsung")
|
116 |
design_prompt = gr.Textbox(label="Design Details", placeholder="E.g., Bold stripes with geometric patterns")
|
|
|
117 |
generate_button = gr.Button("Generate Design")
|
118 |
save_button = gr.Button("Save Design")
|
119 |
with gr.Column(scale=1):
|
|
|
146 |
Start designing today and bring your creative ideas to life!
|
147 |
""")
|
148 |
|
|
|
149 |
interface.launch(debug=True)
|