File size: 12,358 Bytes
ca9d3cb
c907826
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6728031
c907826
 
6728031
c907826
 
6728031
 
c907826
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6728031
 
 
c907826
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e6fd525
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c907826
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6728031
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c907826
 
 
 
cd2da61
c907826
6728031
c907826
 
2976989
c907826
6728031
 
 
 
 
885a5c0
95f0663
e205aba
587b27e
6728031
 
c907826
 
 
 
 
 
 
 
 
 
6728031
 
 
c907826
 
 
e6fd525
c907826
6728031
 
 
c907826
 
 
 
6728031
c907826
 
6728031
c907826
6728031
c907826
e6fd525
 
c907826
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6728031
c907826
 
 
 
 
 
 
 
 
 
 
6728031
 
c907826
 
 
 
 
 
 
 
 
 
 
 
 
 
6728031
 
 
 
 
 
 
 
c907826
 
 
 
 
 
 
 
6728031
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c907826
 
 
 
 
 
 
 
 
 
 
 
 
6728031
 
 
 
c907826
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2976989
c907826
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2976989
c907826
 
 
 
 
 
 
 
6728031
 
 
 
c907826
 
 
 
 
6728031
 
c907826
 
 
 
 
 
 
 
 
 
 
 
 
e6fd525
 
 
 
 
 
 
c907826
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<html>

<head>
  <base href="https://websim.ai/clock-with-ai/">
  </base>
  <title>AI-Powered Clock with Dynamic Backgrounds</title>
  <style>
    body {
      background-color: #1a1a1a;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
      font-family: Arial, sans-serif;
      color: #00ff00;
      transition: background-image 1s ease-in-out;
    }

    #clock {
      font-weight: bold;
      text-shadow: 0 0 10px currentColor;
      z-index: 10;
    }

    #settings-btn {
      position: fixed;
      top: 10px;
      right: 10px;
      background: rgba(0, 255, 0, 0.2);
      border: none;
      color: #00ff00;
      font-size: 16px;
      cursor: pointer;
      z-index: 20;
      padding: 5px 10px;
      border-radius: 5px;
    }

    #settings-panel {
      position: fixed;
      top: 50px;
      right: 10px;
      background: rgba(255, 255, 255, 0.9);
      color: #000;
      padding: 20px;
      border-radius: 10px;
      display: none;
      z-index: 20;
      max-width: 300px;
      max-height: 80vh;
      overflow-y: auto;
    }

    #token-input,
    #prompt-input,
    #clock-color-input,
    #clock-size-input,
    #model-select,
    #generation-interval-input {
      width: 100%;
      margin-bottom: 10px;
    }

    .btn {
      border: none;
      color: white;
      padding: 10px 20px;
      text-align: center;
      text-decoration: none;
      display: inline-block;
      font-size: 16px;
      margin: 4px 2px;
      cursor: pointer;
      border-radius: 5px;
      transition: background-color 0.3s;
    }

    #fullscreen-btn {
      background-color: #4CAF50;
    }

    #fullscreen-btn:hover {
      background-color: #45a049;
    }

    #save-settings {
      background-color: #008CBA;
    }

    #save-settings:hover {
      background-color: #007B9A;
    }

    #test-image {
      background-color: #f44336;
    }

    #test-image:hover {
      background-color: #da190b;
    }

    #reset-prompt {
      background-color: #ff9800;
    }

    #reset-prompt:hover {
      background-color: #e68a00;
    }

    #background-image {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
      z-index: 1;
    }

    label {
      display: block;
      margin-top: 10px;
      margin-bottom: 5px;
    }

    #countdown-bar {
      position: fixed;
      bottom: 0;
      left: 0;
      height: 5px;
      width: 100%;
      background-color: rgba(0, 255, 0, 0.3);
      z-index: 15;
    }

    #countdown-progress {
      height: 100%;
      width: 0%;
      background-color: rgba(0, 255, 0, 0.7);
      transition: width 1s linear;
    }
  </style>
</head>

<body>
  <img id="background-image" alt="Please specify your HF token in the settings to generate images" src="">
  <div id="clock"></div>
  <button id="settings-btn">Settings</button>
  <div id="settings-panel">
    <label for="token-input">Hugging Face Token:</label>
    <input type="password" id="token-input" placeholder="Enter Hugging Face token">

    <label for="model-select">Select Model:</label>
    <select id="model-select">
      <option value="black-forest-labs/FLUX.1-schnell">FLUX.1-schnell</option>
      <option value="black-forest-labs/FLUX.1-dev">FLUX.1-dev</option>
      <option value="XLabs-AI/flux-RealismLora">flux-RealismLora</option>
      <option value="stabilityai/stable-diffusion-xl-base-1.0">Stable Diffusion XL</option>
      <option value="artificialguybr/PixelArtRedmond">PixelArtRedmond</option>
      <option value="linoyts/yarn_art_Flux_LoRA">yarn art style Flux LoRA (to activate LoRA use "yarn art style"</option>
      <option value="stabilityai/stable-diffusion-3.5-large">stable-diffusion-3.5-large</option>
    </select>

    <label for="prompt-input">Custom Prompt:</label>
    <textarea id="prompt-input" rows="4" placeholder="Enter custom prompt (use {time} for current time)"></textarea>

    <label for="clock-color-input">Clock Color:</label>
    <input type="color" id="clock-color-input">

    <label for="clock-size-input">Clock Size (vw):</label>
    <input type="range" id="clock-size-input" min="1" max="20" step="0.1">
    <span id="clock-size-value"></span>

    <label for="generation-interval-input">Image Generation Interval (seconds):</label>
    <input type="number" id="generation-interval-input" min="10" step="1">

    <button id="fullscreen-btn" class="btn">Toggle Fullscreen</button>
    <button id="save-settings" class="btn">Save</button>
    <button id="test-image" class="btn">Test Image Generation</button>
    <button id="reset-prompt" class="btn">Reset Prompt</button>
  </div>
  <div id="countdown-bar">
    <div id="countdown-progress"></div>
  </div>

  <script>
    let hfToken = localStorage.getItem('hfToken') || '';
    let customPrompt = localStorage.getItem('customPrompt') || 'beautiful abstract landscape that suits the time {time}';
    let generationFrequency = parseInt(localStorage.getItem('generationFrequency')) || 150;
    let clockColor = localStorage.getItem('clockColor') || '#00ff00';
    let clockSize = parseFloat(localStorage.getItem('clockSize')) || 8;
    let selectedModel = localStorage.getItem('selectedModel') || 'black-forest-labs/FLUX.1-schnell';
    let imageGenerationInterval;
    let countdownInterval;

    const DEFAULT_PROMPT = 'beautiful abstract landscape that suits the time {time}';

    function updateClock() {
      const now = new Date();
      let hours = now.getHours();
      const minutes = now.getMinutes()
        .toString()
        .padStart(2, '0');
      const seconds = now.getSeconds()
        .toString()
        .padStart(2, '0');
      const ampm = hours >= 12 ? 'PM' : 'AM';

      hours = hours % 12;
      hours = hours ? hours : 12;
      hours = hours.toString()
        .padStart(2, '0');

      const timeString = `${hours}:${minutes}:${seconds} ${ampm}`;
      const clockElement = document.getElementById('clock');
      clockElement.textContent = timeString;
      clockElement.style.color = clockColor;
      clockElement.style.fontSize = `${clockSize}vw`;

      return `${hours}:${minutes} ${ampm}`;
    }

    async function generateImage(prompt) {
      if (!hfToken) return;

      try {
        const response = await fetch(`https://api-inference.huggingface.co/models/${selectedModel}`, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${hfToken}`
          },
          body: JSON.stringify({
            inputs: prompt
          })
        });

        if (!response.ok) {
          const errorData = await response.json();
          throw new Error(`${response.status}: ${errorData.error || 'Unknown error'}`);
        }

        const blob = await response.blob();
        const imageUrl = URL.createObjectURL(blob);
        const backgroundImage = document.getElementById('background-image');

        const newImage = new Image();
        newImage.onload = function() {
          URL.revokeObjectURL(backgroundImage.src);
          backgroundImage.src = this.src;
        };
        newImage.src = imageUrl;
      } catch (error) {
        console.error('Error generating image:', error);
        speakError(`Error generating image. ${error.message}`);
      }
    }

    function speakError(message) {
      if ('speechSynthesis' in window) {
        const utterance = new SpeechSynthesisUtterance(message);
        speechSynthesis.speak(utterance);
      }
    }

    function updateBackgroundImage() {
      const currentTime = updateClock()
        .slice(0, -3);
      const prompt = customPrompt.replace('{time}', currentTime);
      generateImage(prompt);
      startCountdown();
    }

    function startCountdown() {
      const progressBar = document.getElementById('countdown-progress');
      let timeLeft = generationFrequency;

      clearInterval(countdownInterval);
      countdownInterval = setInterval(() => {
        timeLeft--;
        const progress = ((generationFrequency - timeLeft) / generationFrequency) * 100;
        progressBar.style.width = `${progress}%`;

        if (timeLeft <= 0) {
          clearInterval(countdownInterval);
        }
      }, 1000);
    }

    function initializeSettings() {
      document.getElementById('token-input')
        .value = hfToken;
      document.getElementById('prompt-input')
        .value = customPrompt;
      document.getElementById('clock-color-input')
        .value = clockColor;
      document.getElementById('clock-size-input')
        .value = clockSize;
      document.getElementById('clock-size-value')
        .textContent = clockSize + ' vw';
      document.getElementById('model-select')
        .value = selectedModel;
      document.getElementById('generation-interval-input')
        .value = generationFrequency;
    }

    function toggleFullscreen() {
      if (!document.fullscreenElement) {
        document.documentElement.requestFullscreen()
          .catch(err => console.error(err));
      } else {
        if (document.exitFullscreen) {
          document.exitFullscreen();
        }
      }
    }

    function setupImageGenerationInterval() {
      clearInterval(imageGenerationInterval);
      imageGenerationInterval = setInterval(updateBackgroundImage, generationFrequency * 1000);
    }

    setInterval(updateClock, 1000);
    setupImageGenerationInterval();

    updateClock();
    updateBackgroundImage();
    initializeSettings();

    document.getElementById('settings-btn')
      .addEventListener('click', () => {
        const panel = document.getElementById('settings-panel');
        panel.style.display = panel.style.display === 'none' ? 'block' : 'none';
      });

    document.getElementById('fullscreen-btn')
      .addEventListener('click', toggleFullscreen);

    document.getElementById('save-settings')
      .addEventListener('click', () => {
        hfToken = document.getElementById('token-input')
          .value;
        customPrompt = document.getElementById('prompt-input')
          .value;
        clockColor = document.getElementById('clock-color-input')
          .value;
        clockSize = parseFloat(document.getElementById('clock-size-input')
          .value);
        selectedModel = document.getElementById('model-select')
          .value;
        generationFrequency = parseInt(document.getElementById('generation-interval-input')
          .value);

        localStorage.setItem('hfToken', hfToken);
        localStorage.setItem('customPrompt', customPrompt);
        localStorage.setItem('clockColor', clockColor);
        localStorage.setItem('clockSize', clockSize);
        localStorage.setItem('selectedModel', selectedModel);
        localStorage.setItem('generationFrequency', generationFrequency);

        document.getElementById('settings-panel')
          .style.display = 'none';
        updateBackgroundImage();
        setupImageGenerationInterval();
        updateClock();
      });

    document.getElementById('test-image')
      .addEventListener('click', () => {
        updateBackgroundImage();
      });

    document.getElementById('reset-prompt')
      .addEventListener('click', () => {
        customPrompt = DEFAULT_PROMPT;
        document.getElementById('prompt-input')
          .value = customPrompt;
      });

    document.getElementById('clock-size-input')
      .addEventListener('input', (e) => {
        const value = e.target.value;
        document.getElementById('clock-size-value')
          .textContent = value + ' vw';
        clockSize = parseFloat(value);
        updateClock();
      });

    document.getElementById('clock-color-input')
      .addEventListener('input', (e) => {
        clockColor = e.target.value;
        updateClock();
      });

    document.addEventListener('DOMContentLoaded', () => {
      const settingsBtn = document.getElementById('settings-btn');
      const newSettingsBtn = settingsBtn.cloneNode(true);
      settingsBtn.parentNode.replaceChild(newSettingsBtn, settingsBtn);
      newSettingsBtn.addEventListener('click', () => {
        const panel = document.getElementById('settings-panel');
        panel.style.display = panel.style.display === 'none' ? 'block' : 'none';
      });
    });
  </script>
</body>

</html>