Update app.py
Browse files
app.py
CHANGED
@@ -31,7 +31,7 @@ def infer(color_prompt, phone_type_prompt, design_prompt):
|
|
31 |
while True:
|
32 |
response = requests.post(api_url, headers=headers, json=payload)
|
33 |
if response.status_code == 200:
|
34 |
-
speech_text = f"Your
|
35 |
return Image.open(BytesIO(response.content)), speech_text
|
36 |
elif response.status_code == 503:
|
37 |
time.sleep(1)
|
@@ -42,83 +42,52 @@ def infer(color_prompt, phone_type_prompt, design_prompt):
|
|
42 |
else:
|
43 |
raise Exception(f"API Error: {response.status_code}")
|
44 |
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
-
# Custom CSS for
|
47 |
custom_css = """
|
48 |
body {
|
49 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
50 |
margin: 0;
|
51 |
padding: 0;
|
52 |
-
|
53 |
-
color: #333;
|
54 |
}
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
62 |
}
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
margin: 0 15px;
|
68 |
-
transition: color 0.3s;
|
69 |
-
}
|
70 |
-
.navbar a:hover {
|
71 |
-
color: #0056b3;
|
72 |
-
}
|
73 |
-
.avatar-container {
|
74 |
-
text-align: center;
|
75 |
-
margin-bottom: 20px;
|
76 |
-
position: relative;
|
77 |
-
animation: head-move 3s infinite;
|
78 |
-
}
|
79 |
-
.avatar-img {
|
80 |
-
width: 150px;
|
81 |
-
height: 150px;
|
82 |
-
border-radius: 50%;
|
83 |
-
animation: blink 3s infinite, scale 5s infinite;
|
84 |
-
}
|
85 |
-
@keyframes blink {
|
86 |
-
0%, 100% { opacity: 1; }
|
87 |
-
50% { opacity: 0.7; }
|
88 |
-
}
|
89 |
-
@keyframes scale {
|
90 |
-
0%, 100% { transform: scale(1); }
|
91 |
-
50% { transform: scale(1.05); }
|
92 |
}
|
93 |
"""
|
94 |
|
95 |
-
# JavaScript for text-to-speech and
|
96 |
custom_js = """
|
97 |
<script>
|
98 |
document.addEventListener('DOMContentLoaded', function () {
|
99 |
-
// Add
|
100 |
-
const
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
document.body.
|
108 |
-
|
109 |
-
// Add AI assistant avatar and greeting
|
110 |
-
const avatarContainer = document.createElement('div');
|
111 |
-
avatarContainer.classList.add('avatar-container');
|
112 |
-
const avatarImg = document.createElement('img');
|
113 |
-
avatarImg.src = 'https://th.bing.com/th/id/OIP.zeeoSeLcH19kuQ1ABNOGCwHaHU?rs=1&pid=ImgDetMain';
|
114 |
-
avatarImg.alt = "AI Assistant Avatar";
|
115 |
-
avatarImg.classList.add('avatar-img');
|
116 |
-
avatarContainer.appendChild(avatarImg);
|
117 |
-
const greeting = document.createElement('h2');
|
118 |
-
const currentHour = new Date().getHours();
|
119 |
-
greeting.textContent = currentHour < 12 ? "Good Morning!" : currentHour < 18 ? "Good Afternoon!" : "Good Evening!";
|
120 |
-
avatarContainer.appendChild(greeting);
|
121 |
-
document.body.prepend(avatarContainer);
|
122 |
|
123 |
// Text-to-speech functionality
|
124 |
function speak(text) {
|
@@ -140,22 +109,51 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
140 |
with gr.Blocks(css=custom_css) as interface:
|
141 |
gr.HTML(custom_js)
|
142 |
gr.Markdown("# **AI Phone Cover Designer**")
|
143 |
-
with
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
with gr.
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
# Launch the app
|
161 |
interface.launch(debug=True)
|
|
|
31 |
while True:
|
32 |
response = requests.post(api_url, headers=headers, json=payload)
|
33 |
if response.status_code == 200:
|
34 |
+
speech_text = f"Your design is generated with the color '{color_prompt}', mobile type '{phone_type_prompt}', and design '{design_prompt}'."
|
35 |
return Image.open(BytesIO(response.content)), speech_text
|
36 |
elif response.status_code == 503:
|
37 |
time.sleep(1)
|
|
|
42 |
else:
|
43 |
raise Exception(f"API Error: {response.status_code}")
|
44 |
|
45 |
+
# Function to save the design
|
46 |
+
def save_design(image):
|
47 |
+
file_path = "saved_design.png"
|
48 |
+
image.save(file_path)
|
49 |
+
return f"Design saved as {file_path}!"
|
50 |
|
51 |
+
# Custom CSS for animations
|
52 |
custom_css = """
|
53 |
body {
|
54 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
55 |
margin: 0;
|
56 |
padding: 0;
|
57 |
+
overflow: hidden;
|
|
|
58 |
}
|
59 |
+
body::before {
|
60 |
+
content: "";
|
61 |
+
position: fixed;
|
62 |
+
top: 0;
|
63 |
+
left: 0;
|
64 |
+
width: 100%;
|
65 |
+
height: 100%;
|
66 |
+
background: linear-gradient(-45deg, #ff9a9e, #fad0c4, #fbc2eb, #8fd3f4);
|
67 |
+
background-size: 400% 400%;
|
68 |
+
z-index: -1;
|
69 |
+
animation: gradientShift 15s ease infinite;
|
70 |
}
|
71 |
+
@keyframes gradientShift {
|
72 |
+
0% { background-position: 0% 50%; }
|
73 |
+
50% { background-position: 100% 50%; }
|
74 |
+
100% { background-position: 0% 50%; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
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**! Use the 'Design' tab to start creating custom designs.")
|
118 |
+
|
119 |
+
with gr.Tab("Design"):
|
120 |
+
with gr.Row():
|
121 |
+
with gr.Column(scale=1):
|
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):
|
129 |
+
output_image = gr.Image(label="Generated Design")
|
130 |
+
output_message = gr.Textbox(label="AI Assistant Message", interactive=False)
|
131 |
|
132 |
+
# Button Actions
|
133 |
+
generate_button.click(
|
134 |
+
infer,
|
135 |
+
inputs=[color_prompt, phone_type_prompt, design_prompt],
|
136 |
+
outputs=[output_image, output_message],
|
137 |
+
)
|
138 |
+
save_button.click(
|
139 |
+
save_design,
|
140 |
+
inputs=[output_image],
|
141 |
+
outputs=output_message,
|
142 |
+
)
|
143 |
+
|
144 |
+
with gr.Tab("About"):
|
145 |
+
gr.Markdown("""
|
146 |
+
## About AI Phone Cover Maker
|
147 |
+
The **AI Phone Cover Maker** is a cutting-edge tool designed to help users create personalized phone cover designs quickly and easily.
|
148 |
+
Powered by AI, it uses advanced image generation techniques to craft unique, high-quality designs for any mobile device.
|
149 |
+
|
150 |
+
### Features:
|
151 |
+
- Create custom designs using simple prompts.
|
152 |
+
- Generate designs for various phone models.
|
153 |
+
- Save your designs for future use.
|
154 |
+
|
155 |
+
Start designing today and bring your creative ideas to life!
|
156 |
+
""")
|
157 |
|
158 |
# Launch the app
|
159 |
interface.launch(debug=True)
|