-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
337 lines (279 loc) Β· 10.6 KB
/
index.html
File metadata and controls
337 lines (279 loc) Β· 10.6 KB
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<!doctype html>
<html lang="it">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>LeoBot: Il Laboratorio di Leonardo π°</title>
<style>
:root{
--bg-sunny: #fff9c4;
--ink: #37474f;
--card-bg: #fffffffa;
--accent-red: #ff7043;
--accent-blue: #42a5f5;
--accent-green: #66bb6a;
--shadow: 0 10px 25px rgba(0,0,0,0.1);
--radius: 20px;
--font: "Comic Sans MS","Chalkboard SE","Segoe UI Emoji",sans-serif;
}
*{ box-sizing:border-box }
body{
margin:0;
font-family:var(--font);
color:var(--ink);
background:linear-gradient(135deg,var(--bg-sunny) 0%,#81d4fa 100%);
min-height:100vh;
display:flex;
flex-direction:column;
}
header{ padding:15px; text-align:center; }
.brand{
display:inline-flex; align-items:center; gap:15px; background:#fff;
padding:8px 25px; border-radius:50px; box-shadow:0 5px 0 rgba(0,0,0,0.1);
border:3px solid var(--accent-blue);
}
.brand img{ width:50px; height:50px; border-radius:50%; border:2px solid var(--accent-red); object-fit:cover; }
.brand h1{ margin:0; font-size:24px; color:var(--accent-red); }
main{
flex:1; width:95%; max-width:1500px; margin:10px auto;
display: grid; grid-template-columns: 350px 1fr; gap: 25px;
position: relative;
}
.leo-overlay {
position: absolute;
left: 170px;
top: 50%;
transform: translateY(-80%);
z-index: 10;
pointer-events: none;
}
.leo-overlay img {
max-width: 450px;
filter: drop-shadow(10px 10px 20px rgba(0,0,0,0.3));
}
.image-generator-column { display: flex; flex-direction: column; gap: 15px; }
.generator-box {
background:var(--card-bg); padding:15px; border-radius:var(--radius);
box-shadow:var(--shadow); border:4px solid var(--accent-blue);
display: flex; flex-direction: column;
}
.chat-label { font-size: 18px; font-weight: bold; text-align: center; margin-bottom: 10px; }
.mode-toggle {
display: flex;
background: #f0f0f0;
border-radius: 12px;
padding: 4px;
margin-bottom: 15px;
gap: 4px;
border: 1px solid #ddd;
}
.mode-btn {
flex: 1;
border: none;
padding: 10px;
border-radius: 8px;
cursor: pointer;
font-family: inherit;
font-weight: bold;
font-size: 13px;
transition: all 0.2s ease;
background: transparent;
color: #777;
}
.mode-btn.active {
background: var(--accent-blue);
color: white;
}
textarea {
width: 100%; height: 100px; border-radius: 10px; border: 2px solid #ddd;
padding: 12px; font-family: inherit; resize: none; font-size: 14px; margin-bottom: 10px;
}
#btn-generate {
background: var(--accent-blue); color: white; border: none;
border-radius: 10px; padding: 12px; cursor: pointer; font-weight: bold; font-size: 15px;
transition: background 0.3s;
}
#btn-generate:disabled { background: #ccc; cursor: not-allowed; }
#output-polaroid {
display: none;
background:#fff; padding:10px 10px 25px; box-shadow:0 4px 12px rgba(0,0,0,0.1);
border: 3px solid var(--accent-green); transform: rotate(1deg); text-align:center;
position: relative; overflow: hidden;
}
#output-polaroid img {
width:100%; height:250px; object-fit:contain; background: #fafafa; border: 1px solid #eee; transition: opacity 0.5s;
}
.painting-overlay {
display: none; position: absolute; top: 10px; left: 10px; right: 10px;
height: 250px; background: #f4e4bc;
z-index: 5; flex-direction: column; align-items: center; justify-content: center;
animation: pulse 2s infinite ease-in-out;
}
.painting-overlay span { font-size: 40px; animation: rotate 4s infinite linear; }
@keyframes pulse {
0% { background-color: #f4e4bc; }
50% { background-color: #e2d1a6; }
100% { background-color: #f4e4bc; }
}
@keyframes rotate { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.main-iframe-column {
background: #fff; padding: 10px; border-radius: var(--radius);
box-shadow: var(--shadow); border: 4px solid var(--accent-green);
display: flex; flex-direction: column; height: 700px;
}
iframe { flex: 1; width: 100%; border-radius: 14px; border: none; }
footer { background: #333; color: white; padding: 20px; text-align: center; margin-top: auto; }
.key-container input { padding: 5px 10px; border-radius: 5px; border: none; width: 280px; }
@media (max-width:1100px){
main { grid-template-columns: 1fr; }
.leo-overlay { display: none; }
.main-iframe-column { height: 500px; }
}
</style>
</head>
<body>
<header>
<div class="brand">
<img src="images/logo.png" alt="Leo Avatar">
<h1>Il Laboratorio di Leonardo</h1>
</div>
</header>
<main>
<div class="leo-overlay">
<img src="images/leonardo_fullbody.png" alt="Leonardo">
</div>
<div class="image-generator-column">
<div class="generator-box">
<div class="chat-label">ποΈ Pennello Magico</div>
<div class="mode-toggle">
<button id="mode-ai" class="mode-btn active" onclick="setMode('ai')">π€ AI</button>
<button id="mode-search" class="mode-btn" onclick="setMode('search')">π Ricerca</button>
</div>
<textarea id="prompt-input" placeholder="Esempio: Una bicicletta di legno..."></textarea>
<button onclick="handleAction()" id="btn-generate">Disegna ora!</button>
</div>
<div class="polaroid" id="output-polaroid">
<div id="painting-overlay" class="painting-overlay">
<span>π¨</span>
<p id="overlay-text">Sto dipingendo...</p>
</div>
<img id="aiImage" src="" alt="Risultato">
<div class="caption" id="image-caption"></div>
</div>
</div>
<div class="main-iframe-column">
<div class="chat-label">π¬ Chiedi a Leonardo</div>
<iframe src="https://app.edcafe.ai/chatbots/697e216f0710e0ddf2691886" allow="microphone"></iframe>
</div>
</main>
<footer>
<div class="key-container">
π OpenAI Key: <input type="password" id="api-key-input" placeholder="sk-...">
</div>
<p>π° Progetto Didattico - Scuola Primaria - Vigevano</p>
</footer>
<script>
let currentMode = 'ai';
function setMode(mode) {
currentMode = mode;
document.getElementById('mode-ai').classList.toggle('active', mode === 'ai');
document.getElementById('mode-search').classList.toggle('active', mode === 'search');
const btn = document.getElementById("btn-generate");
btn.innerText = mode === 'ai' ? "Disegna ora!" : "Cerca Immagine!";
btn.style.background = mode === 'ai' ? "var(--accent-blue)" : "var(--accent-green)";
}
function handleAction() {
if (currentMode === 'ai') {
generateImage();
} else {
searchWikimedia();
}
}
async function generateImage() {
const key = document.getElementById("api-key-input").value.trim();
const prompt = document.getElementById("prompt-input").value.trim();
const btn = document.getElementById("btn-generate");
const polaroid = document.getElementById("output-polaroid");
const overlay = document.getElementById("painting-overlay");
const overlayText = document.getElementById("overlay-text");
const aiImage = document.getElementById("aiImage");
const caption = document.getElementById("image-caption");
if (!key) { alert("Metti la chiave nel fondo della pagina!"); return; }
if (!prompt) { alert("Cosa vuoi che disegni?"); return; }
btn.disabled = true;
polaroid.style.display = "block";
overlay.style.display = "flex";
overlayText.innerText = "Sto dipingendo...";
aiImage.style.opacity = "0";
caption.innerText = "Attendi, sto creando...";
try {
const response = await fetch("https://api.openai.com/v1/images/generations", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${key}`
},
body: JSON.stringify({
model: "dall-e-3",
prompt: "A renaissance sketch by Leonardo da Vinci on ancient paper, sepia ink, detailed drawing of: " + prompt,
n: 1,
size: "1024x1024"
})
});
const data = await response.json();
if (data.error) throw new Error(data.error.message);
aiImage.src = data.data[0].url;
aiImage.onload = () => {
overlay.style.display = "none";
aiImage.style.opacity = "1";
caption.innerText = "Ecco lo schizzo finito!";
btn.disabled = false;
};
} catch (e) {
alert("Errore: " + e.message);
overlay.style.display = "none";
btn.disabled = false;
}
}
async function searchWikimedia() {
const prompt = document.getElementById("prompt-input").value.trim();
const btn = document.getElementById("btn-generate");
const polaroid = document.getElementById("output-polaroid");
const overlay = document.getElementById("painting-overlay");
const overlayText = document.getElementById("overlay-text");
const aiImage = document.getElementById("aiImage");
const caption = document.getElementById("image-caption");
if (!prompt) { alert("Cosa devo cercare negli archivi?"); return; }
btn.disabled = true;
polaroid.style.display = "block";
overlay.style.display = "flex";
overlayText.innerText = "Cerco negli archivi...";
aiImage.style.opacity = "0";
caption.innerText = "Esploro la biblioteca...";
try {
const searchUrl = `https://commons.wikimedia.org/w/api.php?action=query&format=json&origin=*&prop=pageimages&generator=search&gsrsearch=File:${encodeURIComponent(prompt)}&gsrlimit=1&piprop=thumbnail&pithumbsize=800`;
const response = await fetch(searchUrl);
const data = await response.json();
if (!data.query || !data.query.pages) {
throw new Error("Nessuna immagine trovata per questo termine.");
}
const pages = data.query.pages;
const firstPageId = Object.keys(pages)[0];
const imageUrl = pages[firstPageId].thumbnail.source;
aiImage.src = imageUrl;
aiImage.onload = () => {
overlay.style.display = "none";
aiImage.style.opacity = "1";
caption.innerText = "Ho trovato questo reperto!";
btn.disabled = false;
};
} catch (e) {
alert("Non ho trovato immagini: " + e.message);
overlay.style.display = "none";
caption.innerText = "Ricerca vuota.";
btn.disabled = false;
}
}
</script>
</body>
</html>