Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
|
@@ -212,38 +212,58 @@ MÔ TẢ: ["A cute [object] in line-art style, with soft pastel colors, minimali
|
|
| 212 |
return { score, prediction, description };
|
| 213 |
}
|
| 214 |
|
| 215 |
-
async generateImageFromDescription(description) {
|
| 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 |
-
const data = await response.json();
|
| 244 |
-
const base64 = data.artifacts[0].base64;
|
| 245 |
-
return `data:image/png;base64,${base64}`;
|
| 246 |
-
}
|
| 247 |
|
| 248 |
displayResults(imageUrl, score, prediction) {
|
| 249 |
const imageContainer = document.getElementById('imageContainer');
|
|
|
|
| 212 |
return { score, prediction, description };
|
| 213 |
}
|
| 214 |
|
| 215 |
+
// async generateImageFromDescription(description) {
|
| 216 |
+
// const enhancedPrompt = `${description}`;
|
| 217 |
+
// const seed = Math.floor(Math.random() * 1e6);
|
| 218 |
|
| 219 |
+
// const engineId = 'stable-diffusion-xl-1024-v1-0';
|
| 220 |
+
// const url = `https://api.stability.ai/v1/generation/${engineId}/text-to-image`;
|
| 221 |
|
| 222 |
|
| 223 |
+
// const STABILITY_API_KEY = 'sk-JzOAcde6bqHRjfInzdrNmNjjrCs0LFAvB838xi14OhhEQ06T '; // Dán key của bạn
|
| 224 |
+
|
| 225 |
+
// const response = await fetch(url, {
|
| 226 |
+
// method: 'POST',
|
| 227 |
+
// headers: {
|
| 228 |
+
// 'Content-Type': 'application/json',
|
| 229 |
+
// 'Accept': 'application/json',
|
| 230 |
+
// 'Authorization': `Bearer ${STABILITY_API_KEY}`
|
| 231 |
+
// },
|
| 232 |
+
// body: JSON.stringify({
|
| 233 |
+
// text_prompts: [{ text: enhancedPrompt }],
|
| 234 |
+
// cfg_scale: 7,
|
| 235 |
+
// width: 1024,
|
| 236 |
+
// height: 1024,
|
| 237 |
+
// samples: 1,
|
| 238 |
+
// steps: 30,
|
| 239 |
+
// seed: seed
|
| 240 |
+
// })
|
| 241 |
+
// });
|
| 242 |
+
|
| 243 |
+
// const data = await response.json();
|
| 244 |
+
// const base64 = data.artifacts[0].base64;
|
| 245 |
+
// return `data:image/png;base64,${base64}`;
|
| 246 |
+
// }
|
| 247 |
|
| 248 |
+
async generateImageFromDescription(description) {
|
| 249 |
+
// Using Pollinations AI (free image generation API)
|
| 250 |
+
// This creates an image based on the description from Gemini
|
| 251 |
+
const enhancedPrompt = `${description}, high quality, detailed artwork, colored pencil, cute illustration`;
|
| 252 |
+
const encodedPrompt = encodeURIComponent(enhancedPrompt);
|
| 253 |
+
|
| 254 |
+
// Generate a unique seed to avoid caching
|
| 255 |
+
const seed = Math.floor(Math.random() * 1000000);
|
| 256 |
+
const imageUrl = `https://image.pollinations.ai/prompt/${encodedPrompt}?seed=${seed}&width=512&height=512&model=flux`;
|
| 257 |
+
|
| 258 |
+
// Verify the image loads
|
| 259 |
+
return new Promise((resolve, reject) => {
|
| 260 |
+
const img = new Image();
|
| 261 |
+
img.onload = () => resolve(imageUrl);
|
| 262 |
+
img.onerror = () => reject(new Error('Không thể tạo ảnh render'));
|
| 263 |
+
img.src = imageUrl;
|
| 264 |
+
});
|
| 265 |
+
}
|
| 266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
|
| 268 |
displayResults(imageUrl, score, prediction) {
|
| 269 |
const imageContainer = document.getElementById('imageContainer');
|