File size: 13,219 Bytes
83ffa83 |
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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Phone Cover Designer</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@keyframes gradientShift {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
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;
}
.design-box {
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border-radius: 15px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}
.gallery-item {
transition: transform 0.3s, box-shadow 0.3s;
}
.gallery-item:hover {
transform: scale(1.05);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}
.loading-dots span {
animation: typing 1s infinite ease-in-out;
}
@keyframes typing {
0% { transform: translateY(0); opacity: 0.4; }
50% { transform: translateY(-5px); opacity: 1; }
100% { transform: translateY(0); opacity: 0.4; }
}
</style>
</head>
<body class="min-h-screen font-sans">
<div class="container mx-auto px-4 py-8">
<!-- Header -->
<header class="text-center mb-12">
<h1 class="text-5xl font-bold mb-4 bg-clip-text text-transparent bg-gradient-to-r from-pink-500 to-blue-500">
AI Phone Cover Designer
</h1>
<p class="text-xl text-gray-700">Create custom phone covers with AI</p>
</header>
<!-- Main Content -->
<div class="design-box p-8 max-w-4xl mx-auto">
<!-- Tabs -->
<div class="flex gap-4 mb-8">
<button data-tab="home" class="tab-btn px-6 py-2 rounded-full bg-blue-500 text-white font-semibold">
Home
</button>
<button data-tab="design" class="tab-btn px-6 py-2 rounded-full bg-gray-200 text-gray-700">
Design
</button>
<button data-tab="about" class="tab-btn px-6 py-2 rounded-full bg-gray-200 text-gray-700">
About
</button>
</div>
<!-- Home Tab -->
<div id="home-tab" class="tab-content active">
<h2 class="text-3xl font-bold mb-6 text-gray-800">Welcome</h2>
<div class="grid grid-cols-2 gap-4" id="gallery">
<!-- Gallery items will be dynamically loaded here -->
</div>
</div>
<!-- Design Tab -->
<div id="design-tab" class="tab-content hidden">
<div class="grid grid-cols-1 md:grid-cols-2 gap-8">
<div>
<div class="mb-6">
<label class="block text-gray-700 mb-2 font-semibold">Color</label>
<input type="text" id="color-input" class="w-full p-3 border rounded-lg"
placeholder="E.g., Red">
</div>
<div class="mb-6">
<label class="block text-gray-700 mb-2 font-semibold">Mobile Type</label>
<input type="text" id="type-input" class="w-full p-3 border rounded-lg"
placeholder="E.g., iPhone 15">
</div>
<div class="mb-6">
<label class="block text-gray-700 mb-2 font-semibold">Design Details</label>
<textarea id="design-input" class="w-full p-3 border rounded-lg" rows="3"
placeholder="E.g., Bold stripes with geometric patterns"></textarea>
</div>
<button id="generate-btn" class="w-full bg-blue-500 text-white py-3 rounded-lg font-semibold
hover:bg-blue-600 transition-colors">
Generate Design
</button>
<button id="save-btn" class="w-full mt-4 bg-green-500 text-white py-3 rounded-lg font-semibold
hover:bg-green-600 transition-colors">
Save Design
</button>
</div>
<div>
<div class="border-2 border-dashed border-gray-300 rounded-lg p-4 aspect-square flex items-center justify-center"
id="output-image">
<span class="text-gray-400">Your design will appear here</span>
</div>
<div class="mt-4 p-4 bg-blue-50 rounded-lg" id="ai-message">
<div class="text-blue-600 font-semibold">AI Assistant:</div>
<div id="message-text" class="mt-2"></div>
</div>
</div>
</div>
</div>
<!-- About Tab -->
<div id="about-tab" class="tab-content hidden">
<h2 class="text-3xl font-bold mb-6 text-gray-800">About</h2>
<div class="space-y-4 text-gray-700">
<p>The AI Phone Cover Maker is a cutting-edge tool designed to help users create personalized phone cover designs quickly and easily.</p>
<div class="bg-white p-4 rounded-lg">
<h3 class="font-semibold text-lg mb-2">Features:</h3>
<ul class="list-disc pl-6">
<li>Create custom designs using simple prompts</li>
<li>Generate designs for various phone models</li>
<li>Save your designs for future use</li>
</ul>
</div>
</div>
</div>
<!-- Loading State -->
<div id="loading" class="hidden fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center">
<div class="bg-white p-8 rounded-lg text-center">
<div class="loading-dots space-x-1 mb-4">
<span class="inline-block w-2 h-2 bg-blue-500 rounded-full"></span>
<span class="inline-block w-2 h-2 bg-blue-500 rounded-full"></span>
<span class="inline-block w-2 h-2 bg-blue-500 rounded-full"></span>
</div>
<p class="text-gray-700">Generating your design...</p>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const API_URL = "https://api-inference.huggingface.co/models/artificialguybr/TshirtDesignRedmond-V2";
const tabs = {
home: document.getElementById('home-tab'),
design: document.getElementById('design-tab'),
about: document.getElementById('about-tab')
};
// Tab functionality
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', function() {
// Set all tabs inactive
Object.values(tabs).forEach(tab => tab.classList.add('hidden'));
document.querySelectorAll('.tab-btn').forEach(b =>
b.classList.replace('bg-blue-500', 'bg-gray-200'));
// Activate selected tab
const tabId = this.dataset.tab;
tabs[tabId].classList.remove('hidden');
this.classList.replace('bg-gray-200', 'bg-blue-500');
});
});
// Generate Design
document.getElementById('generate-btn').addEventListener('click', async function() {
const color = document.getElementById('color-input').value;
const type = document.getElementById('type-input').value;
const design = document.getElementById('design-input').value;
if (!color || !type || !design) {
alert('Please fill in all fields');
return;
}
showLoading(true);
try {
const prompt = `A single vertical ${color} colored ${type} back cover featuring a bold ${design} 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.`;
const response = await queryAPI(prompt);
const imageUrl = URL.createObjectURL(response);
// Display image
const output = document.getElementById('output-image');
output.innerHTML = `<img src="${imageUrl}" class="w-full h-full object-contain rounded-lg">`;
// Update message
const message = `Your design is generated with the color '${color}', mobile type '${type}', and design '${design}'.`;
document.getElementById('message-text').textContent = message;
speakMessage(message);
} catch (error) {
alert('Error generating design: ' + error.message);
}
showLoading(false);
});
// Save Design
document.getElementById('save-btn').addEventListener('click', function() {
const img = document.querySelector('#output-image img');
if (!img) {
alert('No design to save');
return;
}
const link = document.createElement('a');
link.download = 'phone-design.png';
link.href = img.src;
link.click();
document.getElementById('message-text').textContent = 'Design saved successfully!';
});
async function queryAPI(prompt) {
const payload = {
inputs: prompt,
parameters: {
negative_prompt: "(worst quality, low quality, lowres, oversaturated, grayscale, bad photo:1.4)",
num_inference_steps: 30,
scheduler: "DPMSolverMultistepScheduler",
}
};
let retries = 0;
while (retries < 5) {
const response = await fetch(API_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (response.ok) return await response.blob();
if (response.status === 503) {
await new Promise(resolve => setTimeout(resolve, 1000));
retries++;
} else {
throw new Error(`API Error: ${response.status}`);
}
}
throw new Error('Server busy, please try again later');
}
function showLoading(show) {
document.getElementById('loading').style.display = show ? 'flex' : 'none';
}
function speakMessage(text) {
const synth = window.speechSynthesis;
const utterance = new SpeechSynthesisUtterance(text);
synth.speak(utterance);
}
// Load sample gallery images
const gallery = document.getElementById('gallery');
['https://via.placeholder.com/300x500/FFB6C1/ffffff?text=Sample+1',
'https://via.placeholder.com/300x500/87CEEB/ffffff?text=Sample+2',
'https://via.placeholder.com/300x500/98FB98/ffffff?text=Sample+3',
'https://via.placeholder.com/300x500/DDA0DD/ffffff?text=Sample+4']
.forEach(url => {
gallery.innerHTML += `
<div class="gallery-item bg-white rounded-lg overflow-hidden">
<img src="${url}" class="w-full h-48 object-cover">
<div class="p-3 text-gray-700">Sample Design</div>
</div>
`;
});
});
</script>
</body>
</html> |