-
Notifications
You must be signed in to change notification settings - Fork 0
/
image-generator-app.html
96 lines (91 loc) · 3.16 KB
/
image-generator-app.html
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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Generador de Imágenes con IA</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.3.4/axios.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
text-align: center;
}
#prompt {
width: 100%;
padding: 10px;
margin-bottom: 10px;
}
#generate {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
#result {
margin-top: 20px;
}
#loading {
display: none;
}
</style>
</head>
<body>
<h1>Generador de Imágenes con IA</h1>
<input type="text" id="prompt" placeholder="Describe la imagen que quieres generar">
<button id="generate">Generar Imagen</button>
<div id="loading">Generando imagen...</div>
<div id="result"></div>
<script>
const generateBtn = document.getElementById('generate');
const promptInput = document.getElementById('prompt');
const resultDiv = document.getElementById('result');
const loadingDiv = document.getElementById('loading');
generateBtn.addEventListener('click', async () => {
const prompt = promptInput.value;
if (!prompt) {
alert('Por favor, ingresa una descripción para la imagen.');
return;
}
loadingDiv.style.display = 'block';
resultDiv.innerHTML = '';
try {
const response = await axios.post(
'https://api.segmind.com/v1/sdxl1.0-txt2img',
{
prompt: prompt,
negative_prompt: "blurry, bad",
samples: 1,
scheduler: "dpmpp_2m",
num_inference_steps: 25,
guidance_scale: 7,
seed: 2414,
img_width: 512,
img_height: 512,
},
{
headers: {
// x-api-key: '',
'Content-Type': 'application/json',
},
responseType: 'arraybuffer',
}
);
const blob = new Blob([response.data], { type: 'image/png' });
const imageUrl = URL.createObjectURL(blob);
const img = document.createElement('img');
img.src = imageUrl;
resultDiv.appendChild(img);
} catch (error) {
console.error('Error:', error);
resultDiv.textContent = 'Hubo un error al generar la imagen. Por favor, intenta de nuevo.';
} finally {
loadingDiv.style.display = 'none';
}
});
</script>
</body>
</html>