row_id int64 0 48.4k | init_message stringlengths 1 342k | conversation_hash stringlengths 32 32 | scores dict |
|---|---|---|---|
19,293 | Write a C# program to create a text file and write the following Text in it, then open the file automatically with coding (Mimicking double-clicking on it) | 5c45765aff7c0610c830452d08f2f612 | {
"intermediate": 0.4675723612308502,
"beginner": 0.21652117371559143,
"expert": 0.31590646505355835
} |
19,294 | const modelUrl = ‘https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited’;
const modelToken = ‘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’;
const progressBarFilled = document.querySelector(‘.progress-bar-filled’);
const imageCanvas = document.getElementById(‘imageCanvas’);
const ctx = imageCanvas.getContext(‘2d’);
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: ‘POST’,
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get(‘estimated_time’);
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById(‘autoQueueCheckbox’).checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById(‘timeoutInput’).value) * 1000;
const interval = parseInt(document.getElementById(‘intervalInput’).value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById(‘inputText’).value;
const numAttempts = parseInt(document.getElementById(‘numAttemptsInput’).value);
progressBarFilled.style.width = ‘0%’;
progressBarFilled.style.backgroundColor = ‘green’;
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + ‘%’;
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = ‘100%’;
progressBarFilled.style.backgroundColor = ‘darkmagenta’;
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById(‘autoQueueCheckbox’).checked;
}
progressBarFilled.style.width = ‘100%’;
progressBarFilled.style.height = ‘2px’;
progressBarFilled.style.backgroundColor = ‘green’;
isGenerating = false;
}
</script>
</body>
</html>
To keep the .canvas-container within a certain range in vh, you can use a combination of CSS variables and calculations. Update the calc statement in the width property of .canvas-container as follows:
.canvas-container {
position: relative;
width: calc(100vw / 512);
max-width: calc(50vh * 512);
margin: auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
Here, calc(100vw / 512) sets the width of the container as a fraction of the viewport width (100vw) divided by 512. This ensures that the container width remains proportional to the viewport width while maintaining its px size.
Additionally, max-width: calc(50vh * 512) sets the maximum width of the container to the product of 50vh and 512. This restricts the container width to 50% of the viewport height while maintaining its px size.
This way, the .canvas-container stays within the specified range in vh, and the image inside it remains aligned.
need this “.canvas-container” to auto-full-scale +/- “vh” on window resize but keep the image canvas inside unexpandable beyond “.canvas-container” itself and as well the image should has a “px” dimension, because it gets reduced in quality on resize if something other than “px”. I don’t understand wtf is happening there.
I apologize for the confusion. To achieve the desired behavior where .canvas-container auto-scales on window resize and the image canvas remains within the container without expanding beyond it, you can modify the CSS and add a JavaScript event handler.
Modify the CSS for .canvas-container as follows:
.canvas-container {
position: relative;
width: 100%;
max-width: calc(50vh * 512px);
margin: auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
Here, width: 100% allows the container to take up the full width of its parent element. max-width: calc(50vh * 512px) restricts the maximum width of the container to 50% of the viewport height multiplied by 512 pixels.
Next, you’ll need to add a JavaScript event handler to handle the window resize event and update the width of the container and the canvas accordingly.
window.addEventListener(‘resize’, handleResize);
function handleResize() {
const container = document.querySelector(‘.canvas-container’);
const canvas = document.getElementById(‘imageCanvas’);
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.style.width = ${canvasWidth}px;
canvas.style.height = ${canvasHeight}px;
}
In the handleResize function, we get the current width and height of the container and calculate the width and height of the canvas based on the aspect ratio of the image. This ensures that the image canvas always fits within the container without expanding beyond it. We then set the width and height of the canvas using inline styles in pixels.
Call the handleResize function after defining it to initialize the canvas dimensions on page load.
handleResize();
This ensures that the canvas is correctly sized on initial page load.
ok, image seem to fit but aspect-ratio got fuckt up. any ideas?
I apologize for the confusion. To fix the aspect ratio issue, you need to update the JavaScript code that handles the window resize event.
Instead of setting the width and height of the canvas using inline styles, we should update the canvas width and height attributes directly in JavaScript. This will ensure that the canvas maintains its aspect ratio properly.
Here’s the modified JavaScript code:
function handleResize() {
const container = document.querySelector(‘.canvas-container’);
const canvas = document.getElementById(‘imageCanvas’);
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
const ctx = canvas.getContext(‘2d’);
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
}
In this updated code, we set the width and height attributes of the canvas directly using canvas.width and canvas.height. We then clear the canvas using ctx.clearRect() and redraw the image with the correct dimensions using ctx.drawImage().
Make sure to call the handleResize() function after defining it to initialize the canvas dimensions on page load:
handleResize();
With this change, the aspect ratio of the image canvas should be maintained correctly when the window is resized.
ReferenceError: img is not defined
Apologies for the oversight. It seems that I missed a part in the code where img is defined. To fix this issue, we need to create a new Image object and load the image URL.
Please update the JavaScript code as follows:
function handleResize() {
const container = document.querySelector(‘.canvas-container’);
const canvas = document.getElementById(‘imageCanvas’);
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
const ctx = canvas.getContext(‘2d’);
ctx.clearRect(0, 0, canvas | e9630665ec0f656f6f285f5f7f8892bc | {
"intermediate": 0.3281908929347992,
"beginner": 0.36871108412742615,
"expert": 0.3030979633331299
} |
19,295 | Can you please show me how to write the VBA code and how to create the form for the following event:
Every time I enter a number (not a letter) into B:B pop up a Form that
Has entries for Start Time & End Time.
After entering the values in the Form and I click OK,
the Start time entry is inserted into column 'AD' on the same row as my active cell in column B
The End Time entry is inserted into column 'AE' on the same row as my active cell in column B. | 55e810fed49eb7e656ca92e7e2171e4e | {
"intermediate": 0.5858469009399414,
"beginner": 0.15603859722614288,
"expert": 0.2581145167350769
} |
19,296 | 把下面Matlab代码转换成Python:function arrayOut = filterAndSwap2D(arrayIn, w, h, stepS)
arrayOut = zeros(w * h, 1);
% B3 spline wavelet configuration
% the convolution kernel is {1/16, 1/4, 3/8, 1/4, 1/16}
w2 = 1/16;
w1 = 1/4;
w0 = 3/8;
w0idx = 1;
for y = 1:h % loop over the second dimension
% manage the left border with mirror symmetry
arrayOutIter = y; % output pointer initialization, we swap dimensions at this point
w1idx1 = w0idx + stepS - 1;
w2idx1 = w1idx1 + stepS;
w1idx2 = w0idx + stepS;
w2idx2 = w1idx2 + stepS;
cntX = 1;
while cntX <= stepS
arrayOut(arrayOutIter) = w2 * (arrayIn(w2idx1) + arrayIn(w2idx2))+ w1 * (arrayIn(w1idx1) + arrayIn(w1idx2)) + w0 * arrayIn(w0idx);
w1idx1 = w1idx1 - 1;
w2idx1 = w2idx1 - 1;
w1idx2 = w1idx2 + 1;
w2idx2 = w2idx2 + 1;
w0idx = w0idx + 1;
arrayOutIter = arrayOutIter + h;
cntX = cntX + 1;
end
w1idx1 = w1idx1 + 1;
while cntX <= 2 * stepS
arrayOut(arrayOutIter) = w2 * (arrayIn(w2idx1) + arrayIn(w2idx2))+ w1 * (arrayIn(w1idx1) + arrayIn(w1idx2)) + w0 * arrayIn(w0idx);
w1idx1 = w1idx1 + 1;
w2idx1 = w2idx1 - 1;
w1idx2 = w1idx2 + 1;
w2idx2 = w2idx2 + 1;
w0idx = w0idx + 1;
arrayOutIter = arrayOutIter + h;
cntX = cntX + 1;
end
w2idx1 = w2idx1 + 1;
% filter the center area of the image (no border issue)
while cntX <= w - 2 * stepS
arrayOut(arrayOutIter) = w2 * (arrayIn(w2idx1) + arrayIn(w2idx2))+ w1 * (arrayIn(w1idx1) + arrayIn(w1idx2)) + w0 * arrayIn(w0idx);
w1idx1 = w1idx1 + 1;
w2idx1 = w2idx1 + 1;
w1idx2 = w1idx2 + 1;
w2idx2 = w2idx2 + 1;
w0idx = w0idx + 1;
arrayOutIter = arrayOutIter + h;
cntX = cntX + 1;
end
w2idx2 = w2idx2 - 1;
% manage the right border with mirror symmetry
while cntX <= w - stepS
arrayOut(arrayOutIter) = w2 * (arrayIn(w2idx1) + arrayIn(w2idx2))+ w1 * (arrayIn(w1idx1) + arrayIn(w1idx2)) + w0 * arrayIn(w0idx);
w1idx1 = w1idx1 + 1;
w2idx1 = w2idx1 + 1;
w1idx2 = w1idx2 + 1;
w2idx2 = w2idx2 - 1;
w0idx = w0idx + 1;
arrayOutIter = arrayOutIter + h;
cntX = cntX + 1;
end
w1idx2 = w1idx2 - 1;
while cntX <= w
arrayOut(arrayOutIter) = w2 * (arrayIn(w2idx1) + arrayIn(w2idx2))+ w1 * (arrayIn(w1idx1) + arrayIn(w1idx2)) + w0 * arrayIn(w0idx);
w1idx1 = w1idx1 + 1;
w2idx1 = w2idx1 + 1;
w1idx2 = w1idx2 - 1;
w2idx2 = w2idx2 - 1;
w0idx = w0idx + 1;
arrayOutIter = arrayOutIter + h;
cntX = cntX + 1;
end
end
end | aca4fecb5a5343917e9a6c6d92e1d3a8 | {
"intermediate": 0.2387770563364029,
"beginner": 0.5590717792510986,
"expert": 0.20215119421482086
} |
19,297 | Write a C# program to delete a folder with all of its content (files & sub-folders) | 63ed29ef4df911240ca5d7a3dffd9d4c | {
"intermediate": 0.3943057954311371,
"beginner": 0.20675095915794373,
"expert": 0.3989431858062744
} |
19,298 | 把下面Matlab代码转成Python:function Result = WaveletFilter(image,aMinRadius,aMaxRadius,scaleThreshold)
% Based on the code of Institut Pasteur
% Image : input image matrix, 8-bit or 16-bit grey
% aMinRadius : minimal expected spot radius in pixel
% aMaxRadius : maximal expected spot radius in pixel
% scaleThreshold : N x Sigma of Standard Deviation (we can begin with 2 or 3 )
height = size(image,1);
width = size(image,2);
Result = zeros(height, width);
availableScale = [1, 3, 7, 13, 25]; % in pixel
scalesList = logical([false, false, false, false, false]);
%Set scaleList accroding to min and max radius
isEnable =false;
for i = 1:5
if availableScale(i) >= aMinRadius * 2 && availableScale(i) <= aMaxRadius * 2
scalesList(i) = true;
isEnable = true;
end
end
if ~isEnable
for i = 1:5
if availableScale(i) >= aMinRadius * 2
scalesList(i - 1) = true;
break;
end
end
end
maxScale = 0;
% minScale = 0;
% find the max scale number in scalesList[]
findMin = false;
for i = 1:length(scalesList)
if scalesList(i)
if ~findMin
findMin = true;
% minScale = i + 1;
end
maxScale = i;
end
end
if maxScale == 0
return;
end
% check image dimensions
minSize = 5 + (2^(maxScale - 1) - 1) * 4;
if width < minSize || height < minSize
return;
end
image = image';
pixels = image(:);
% decompose the image
scales = WaveletScales2D(pixels, width, height, maxScale);
coefficients = b3WaveletCoefficients2D(scales, pixels, maxScale);
% Apply threshold to coefficients but not last one (residual)
for i = 1:(size(coefficients,1)-1)
coefficients(i,:) = filter_wat(coefficients(i,:), i, maxScale, scalesList, scaleThreshold);
end
% fill of 0 the residual image
coefficients(end,:)= 0;
Arrayout = SpotConstruction2D(coefficients, maxScale, width * height, scalesList);
Result = reshape (Arrayout,width,height);
Result = Result';
end
% Wavelet scale images for a 2D image (Copy from Institut Pasteur)
function resArray = WaveletScales2D(dataIn, w, h, numScales)
% step between non zero coefficients of the convolution kernel
stepS = 0;
resArray = zeros(numScales, numel(dataIn));
prevArray = dataIn; % array to filter, original data for the first scale
currentArray = []; % filtered array
% for each scale
for s = 1:numScales
stepS = 2^(s - 1); % compute the step between non zero coefficients of the convolution kernel = 2^(scale-1)
% convolve along the x direction and swap dimensions
currentArray = filterAndSwap2D(prevArray, w, h, stepS);
% swap current and previous array pointers
if s == 1
prevArray = currentArray; % the filtered array becomes the array to filter
currentArray = zeros(w * h, 1); % allocate memory for the next dimension filtering (preserve original data)
else
tmp = currentArray;
currentArray = prevArray; % the filtered array becomes the array to filter
prevArray = tmp; % the filtered array becomes the array to filter
end
% convolve along the y direction and swap dimensions
currentArray = filterAndSwap2D(prevArray, h, w, stepS); % swap size of dimensions
% swap current and previous array pointers
tmp = currentArray;
currentArray = prevArray;
prevArray = tmp;
resArray(s, :) = zeros(w * h, 1); % allocate memory to store the filtered array
resArray(s, :) = prevArray;
end
end
function waveletCoefficients = b3WaveletCoefficients2D(scaleCoefficients, originalImage, numScales)
% maxScales wavelet images to store, + one image for the low pass residual
waveletCoefficients = zeros(numScales + 1, numel(originalImage));
% compute wavelet coefficients as the difference between scale coefficients of subsequent scales
iterPrev = originalImage; % the finest scale coefficient is the difference between the original image and the first scale.
j = 1;
while j <= numScales
iterCurrent = scaleCoefficients(j,:);
wCoefficients = zeros(1,numel(originalImage));
for i = 1:numel(originalImage)
wCoefficients(i) = iterPrev(i) - iterCurrent(i);
end
waveletCoefficients(j,:) = wCoefficients;
iterPrev = iterCurrent;
j = j + 1;
end
% residual low pass image is the last wavelet Scale
waveletCoefficients(numScales+1,:) = scaleCoefficients(numScales,:);
end | 3feeffe72e2d71b0cab9d077fe8a2a42 | {
"intermediate": 0.31172752380371094,
"beginner": 0.4098510444164276,
"expert": 0.2784213423728943
} |
19,299 | Can you please write me a VBA code that can do the following:
When I select a range in sheet 'Overtime' and then Click a button,
the VBA code checks the name in sheet 'OTForm' cell B4
Then for all matching values in sheet 'Overtime' C:C of the selection.
Copy the row values to sheet 'OTForm' starting from row 11 in the following order:
Value on same row of column A in 'Overtime' to column A in 'OvTForm'
Value on same row of column B in 'Overtime' to column E in 'OvTForm'
Value on same row of column D in 'Overtime' to column B in 'OvTForm'
Value on same row of column AD in 'Overtime' to column C in 'OvTForm'
Value on same row of column AE in 'Overtime' to column D in 'OvTForm'
If there are no matching values in the selection then pop up a warning:
"Name of Staff not found in selection, check Name entered in Overtime Form' | 1ecd756714665ccde82b6dfec903efef | {
"intermediate": 0.505373477935791,
"beginner": 0.12121961265802383,
"expert": 0.37340691685676575
} |
19,300 | """
Prepare the Shakespeare dataset for character-level language modeling.
So instead of encoding with GPT-2 BPE tokens, we just map characters to ints.
Will save train.bin, val.bin containing the ids, and meta.pkl containing the
encoder and decoder and some other related info.
"""
import os
import pickle
import requests
import numpy as np
# download the tiny shakespeare dataset
input_file_path = os.path.join(os.path.dirname(__file__), 'input.txt')
if not os.path.exists(input_file_path):
data_url = 'https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt'
with open(input_file_path, 'w') as f:
f.write(requests.get(data_url).text)
with open(input_file_path, 'r') as f:
data = f.read()
print(f"length of dataset in characters: {len(data):,}")
# get all the unique characters that occur in this text
chars = sorted(list(set(data)))
vocab_size = len(chars)
print("all the unique characters:", ''.join(chars))
print(f"vocab size: {vocab_size:,}")
# create a mapping from characters to integers
stoi = { ch:i for i,ch in enumerate(chars) }
itos = { i:ch for i,ch in enumerate(chars) }
def encode(s):
return [stoi[c] for c in s] # encoder: take a string, output a list of integers
def decode(l):
return ''.join([itos[i] for i in l]) # decoder: take a list of integers, output a string
# create the train and test splits
n = len(data)
train_data = data[:int(n*0.9)]
val_data = data[int(n*0.9):]
# encode both to integers
train_ids = encode(train_data)
val_ids = encode(val_data)
print(f"train has {len(train_ids):,} tokens")
print(f"val has {len(val_ids):,} tokens")
# export to bin files
train_ids = np.array(train_ids, dtype=np.uint16)
val_ids = np.array(val_ids, dtype=np.uint16)
train_ids.tofile(os.path.join(os.path.dirname(__file__), 'train.bin'))
val_ids.tofile(os.path.join(os.path.dirname(__file__), 'val.bin'))
# save the meta information as well, to help us encode/decode later
meta = {
'vocab_size': vocab_size,
'itos': itos,
'stoi': stoi,
}
with open(os.path.join(os.path.dirname(__file__), 'meta.pkl'), 'wb') as f:
pickle.dump(meta, f)
# length of dataset in characters: 1115394
# all the unique characters:
# !$&',-.3:;?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
# vocab size: 65
# train has 1003854 tokens
# val has 111540 tokens 请问这段是什么意思 | b6bd771fdd2428580f1af14302ac82b7 | {
"intermediate": 0.3015677034854889,
"beginner": 0.40682318806648254,
"expert": 0.2916090786457062
} |
19,301 | using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NextPage : MonoBehaviour
{
public static int b;
public AudioSource Wrong;
static public AudioSource Wrong2 = Wrong;
/*public Image ColorButton1;*/
public Image ColorButton2;
public Image ColorButton3;
public Image ColorButton4;
/*public void Click1()
{
b = 1;
if (b != breed.i)
{
ColorButton1.color = new Color(0.5f, 0f, 0f, 1f);
Wrong.Play();
}
}*/
public void Click2()
{
b = 2;
if (b != breed.i)
{
ColorButton2.color = new Color(0.5f, 0f, 0f, 1f);
Wrong.Play();
}
}
public void Click3()
{
b = 3;
if (b != breed.i)
{
ColorButton3.color = new Color(0.5f, 0f, 0f, 1f);
Wrong.Play();
}
}
public void Click4()
{
b = 4;
if (b != breed.i)
{
ColorButton4.color = new Color(0.5f, 0f, 0f, 1f);
Wrong.Play();
}
}
} | 03db979f726e311e1f01f9d736a6e301 | {
"intermediate": 0.4036353826522827,
"beginner": 0.3019654154777527,
"expert": 0.294399231672287
} |
19,302 | #include <iostream>
#include <string>
#include <unordered_map>
int main() {
std::string s;
std::cin >> s;
std::unordered_map<char, int> letterCounts;
for (char letter : s) {
letterCounts[letter]++;
}
int maxWords = INT_MAX;
maxWords = std::min(maxWords, letterCounts[‘s’]);
maxWords = std::min(maxWords, letterCounts[‘h’]);
maxWords = std::min(maxWords, letterCounts[‘e’]/2);
maxWords = std::min(maxWords, letterCounts[‘r’]/2);
maxWords = std::min(maxWords, letterCounts[‘i’]);
maxWords = std::min(maxWords, letterCounts[‘f’]);
std::cout << maxWords << std::endl;
return 0;
}
при выполнении этого кода происходит ошибка компиляции исправь это | 662f35c3946dfbe067846c4d807007a9 | {
"intermediate": 0.38290518522262573,
"beginner": 0.34686750173568726,
"expert": 0.270227313041687
} |
19,303 | import os
import pickle
import requests
# download the Chinese web novel dataset
input_file_path = os.path.join(os.path.dirname(file), ‘input.txt’)
if not os.path.exists(input_file_path):
data_url = ‘https://path_to_chinese_web_novel_dataset.txt’
with open(input_file_path, ‘w’, encoding=‘utf-8’) as f:
f.write(requests.get(data_url).text)
with open(input_file_path, ‘r’, encoding=‘utf-8’) as f:
data = f.read()
print(f"dataset length in characters: {len(data):,}")
# create the train and test splits
n = len(data)
train_data = data[:int(n0.9)]
val_data = data[int(n0.9):]
# export to text files
with open(os.path.join(os.path.dirname(file), ‘train.txt’), ‘w’, encoding=‘utf-8’) as f:
f.write(train_data)
with open(os.path.join(os.path.dirname(file), ‘val.txt’), ‘w’, encoding=‘utf-8’) as f:
f.write(val_data)
# save the meta information as well, to help us encode/decode later
vocab = list(set(data))
vocab_size = len(vocab)
meta = {
‘vocab_size’: vocab_size,
‘vocab’: vocab,
}
with open(os.path.join(os.path.dirname(file), ‘meta.pkl’), ‘wb’) as f:
pickle.dump(meta, f)
# dataset length in characters: 1,115,394这个程序一直报错 | 7118361abf1ef696134e30ed6fc83430 | {
"intermediate": 0.4907606840133667,
"beginner": 0.32484275102615356,
"expert": 0.18439653515815735
} |
19,304 | I have this code below that I would like to use.
Unfortunately after I OK my selection, it can not make a match between sheet 'OTForm' cell B4 and the selection in sheet 'Overtime'.
Sub CopyMatchingRows()
Dim wsOvertime As Worksheet
Dim wsOTForm As Worksheet
Dim nameToFind As String
Dim selectedRange As Range
Dim cell As Range
Dim matchFound As Boolean
Dim copyRow As Range
Dim lastRow As Long
Dim i As Long
' Set references to the worksheets
Set wsOvertime = ThisWorkbook.Sheets("Overtime")
Set wsOTForm = ThisWorkbook.Sheets("OTForm")
' Get the name to find from cell B4 in 'OTForm'
nameToFind = wsOTForm.Range("B4").Value
' Get the selected range in 'Overtime'
On Error Resume Next
Set selectedRange = Application.InputBox("Please select a range in 'Overtime'", Type:=8)
On Error GoTo 0
' Check if a range was selected
If selectedRange Is Nothing Then
MsgBox "No range selected. Please try again.", vbExclamation
Exit Sub
End If
' Check if the name exists in the selected range
For Each cell In selectedRange.Columns(3).Cells
'If Trim(UCase(cell.Value)) = Trim(UCase(nameToFind)) Then
If cell.Value = nameToFind Then
matchFound = True
Exit For
End If
Next cell
' Copy matching rows to 'OTForm'
If matchFound Then
lastRow = wsOTForm.Cells(Rows.Count, 1).End(xlUp).Row
For Each cell In selectedRange.Columns(3).Cells
If cell.Value = nameToFind Then
Set copyRow = cell.EntireRow
i = i + 1
wsOTForm.Cells(lastRow + i + 10, 1).Value = copyRow.Cells(1, 1).Value
wsOTForm.Cells(lastRow + i + 10, 2).Value = copyRow.Cells(1, 4).Value
wsOTForm.Cells(lastRow + i + 10, 3).Value = copyRow.Cells(1, 30).Value
wsOTForm.Cells(lastRow + i + 10, 4).Value = copyRow.Cells(1, 31).Value
wsOTForm.Cells(lastRow + i + 10, 5).Value = copyRow.Cells(1, 32).Value
End If
Next cell
MsgBox "Matching rows copied to 'OTForm'.", vbInformation
Else
MsgBox "Name of Staff not found in selection. Please check the name entered in 'OTForm'.", vbExclamation
End If
End Sub | d3fc840ae5994f96e93ae64f463ef25b | {
"intermediate": 0.4578130543231964,
"beginner": 0.32165300846099854,
"expert": 0.22053401172161102
} |
19,305 | Write a query to display the manager name, department name, department phone number, employee name, customer name, invoice date, and invoice total for the department manager of the employee who made a sale to a customer whose last name is Hagan on May 18, 2015 (Figure P7.64). I don't have manager table get data from lg table | ff1dda6121af2e821bb10b3af38c1ec3 | {
"intermediate": 0.5433754324913025,
"beginner": 0.19168536365032196,
"expert": 0.26493915915489197
} |
19,306 | 请你以gpt宗师身份检查下面代码,并全部修改,因为代码无法运行import os
import pickle
import requests
# 下载中文网络小说数据集
input_file_path = os.path.join(os.path.dirname(file), ‘input.txt’)
if not os.path.exists(input_file_path):
data_url = ‘https://path_to_chinese_web_novel_dataset.txt’
with open(input_file_path, ‘w’, encoding=‘utf-8’) as f:
f.write(requests.get(data_url).text)
with open(input_file_path, ‘r’, encoding=‘utf-8’) as f:
data = f.read()
print(f"dataset length in characters: {len(data):,}")
# 创建训练集和验证集的拆分
n = len(data)
train_data = data[:int(n * 0.9)]
val_data = data[int(n * 0.9):]
# 导出文本文件
with open(os.path.join(os.path.dirname(file), ‘train.txt’), ‘w’, encoding=‘utf-8’) as f:
f.write(train_data)
with open(os.path.join(os.path.dirname(file), ‘val.txt’), ‘w’, encoding=‘utf-8’) as f:
f.write(val_data)
# 保存元数据信息,以便后续编码/解码
vocab = list(set(data))
vocab_size = len(vocab)
meta = {
‘vocab_size’: vocab_size,
‘vocab’: vocab,
}
with open(os.path.join(os.path.dirname(file), ‘meta.pkl’), ‘wb’) as f:
pickle.dump(meta, f)
print(“数据预处理和保存完毕!”) | c86f2eb087533539723b3efff503bdc3 | {
"intermediate": 0.33613452315330505,
"beginner": 0.4855644106864929,
"expert": 0.17830106616020203
} |
19,307 | need also to update actual resizing on each new image. because it has a nice scale-up animation effect on initial preloading, but then it simply swithing in container statically. no, it sill swithing in container statically. any ideas how to rescale each consequencing image as on initial one? maybe there’s something else?
My apologies for the confusion. To achieve the desired scale-up animation effect for each subsequent image, you can modify the generateImage() function to clear the canvas and apply the animation effect before drawing the new image. One approach is to use JavaScript to manually animate the scaling of the canvas element.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(–font-size, 16px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(–font-size, 16px);
--font-family: var(–font-family, monospace);
--font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: ‘’;
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class=‘container’>
<div class=‘control-container’>
<div class=‘input-field-container’>
<h1 class=‘title’ style=‘margin-left: 10px;margin-right: 10px;margin-top: 10px;’>T2I AI UI</h1>
<input id=‘inputText’ type=‘text’ value=‘armoured girl riding an armored cock’ class=‘input-field’ style=‘flex: 1;margin-top: -6px;’>
<div class=‘gen-button-container’>
<button onclick=‘generateImage()’ class=‘gen-button’ style=‘border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;’>Gen Img</button>
</div>
</div>
</div>
<div class=‘independent-container’>
<label for=‘autoQueueCheckbox’ style=‘margin-left: 10px;margin-right: 5px;’>Auto Queue:</label>
<input type=‘checkbox’ id=‘autoQueueCheckbox’ onchange=‘autoQueueChanged()’>
<label for=‘numAttemptsInput’ style=‘margin-left: 10px;margin-right: 5px;’>Retry Attempts:</label>
<input type=‘number’ id=‘numAttemptsInput’ value=‘50’ min=‘2’ max=‘1000’ style=‘width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;’>
<label for=‘intervalInput’ style=‘margin-left: 10px;margin-right: 5px;’>Interval (sec):</label>
<input type=‘number’ id=‘intervalInput’ value=‘25’ min=‘1’ max=‘300’ style=‘width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;’>
<label for=‘timeoutInput’ style=‘margin-left: 10px;margin-right: 5px;’>Timeout (sec):</label>
<input type=‘number’ id=‘timeoutInput’ value=‘120’ min=‘12’ max=‘600’ style=‘width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;’>
</div>
<div class=‘canvas-container’>
<canvas id=‘imageCanvas’ class=‘image-canvas’></canvas>
<div class=‘progress-bar’>
<div class=‘progress-bar-filled’></div>
</div>
</div>
<script>
const modelUrl = ‘https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited’;
const modelToken = ‘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’;
const progressBarFilled = document.querySelector(‘.progress-bar-filled’);
const imageCanvas = document.getElementById(‘imageCanvas’);
const ctx = imageCanvas.getContext(‘2d’);
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: ‘POST’,
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get(‘estimated_time’);
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById(‘autoQueueCheckbox’).checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById(‘timeoutInput’).value) * 1000;
const interval = parseInt(document.getElementById(‘intervalInput’).value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById(‘inputText’).value;
const numAttempts = parseInt(document.getElementById(‘numAttemptsInput’).value);
progressBarFilled.style.width = ‘0%’;
progressBarFilled.style.backgroundColor = ‘green’;
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + ‘%’;
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = ‘100%’;
progressBarFilled.style.backgroundColor = ‘darkmagenta’;
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById(‘autoQueueCheckbox’).checked;
}
progressBarFilled.style.width = ‘100%’;
progressBarFilled.style.height = ‘2px’;
progressBarFilled.style.backgroundColor = ‘green’;
isGenerating = false;
}
window.addEventListener(‘resize’, handleResize);
function handleResize() {
const container = document.querySelector(‘.canvas-container’);
const canvas = document.getElementById(‘imageCanvas’);
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.style.width = ${canvasWidth}px;
canvas.style.height = ${canvasHeight}px;
requestAnimationFrame(handleResize); // Continuously update aspect ratio
}
document.addEventListener(‘DOMContentLoaded’, function() {
handleResize();
});
</script>
</body>
</html> | 53dcaaa0cd97c384e5bbf7b169088186 | {
"intermediate": 0.2931181788444519,
"beginner": 0.5598857998847961,
"expert": 0.14699603617191315
} |
19,308 | using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class button1 : MonoBehaviour
{
public Image ColorButton1;
public AudioSource Wrong;
void OnMouseDown()
{
NextPage.b = 1;
if (NextPage.b != breed.i)
{
ColorButton1.color = new Color(0.5f, 0f, 0f, 1f);
Wrong.Play();
}
}
} | 78335bfc830ee801b3e9966fd3dc6abc | {
"intermediate": 0.40059539675712585,
"beginner": 0.36278021335601807,
"expert": 0.2366243451833725
} |
19,309 | Write a query to display the manager name, department name, department phone number, employee name, customer name, invoice date, and invoice total for the department manager of the employee who made a sale to a customer whose last name is Hagan on May 18, 2015 (Figure P7.64). from lg table by using join function on my tsql but I don't have manager table at all | f824bdfdc44c9a5a42e0d237cc94a6ab | {
"intermediate": 0.5360130667686462,
"beginner": 0.23075471818447113,
"expert": 0.23323220014572144
} |
19,310 | SyntaxError: unlabeled break must be inside loop or switch ? why? where?: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
// Apply effects to each received image
receivedImages.forEach((receivedImg, index) => {
const imageWidth = receivedImg.naturalWidth;
const imageHeight = receivedImg.naturalHeight;
const aspectRatio = receivedImg.width / receivedImg.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.drawImage(receivedImg, 0, 0, canvasWidth, canvasHeight);
});
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
function handleResize() {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.style.width = `${canvasWidth}px`;
canvas.style.height = `${canvasHeight}px`;
requestAnimationFrame(handleResize); // Continuously update aspect ratio
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | e91ee4533808378a4ee84ed178f23a26 | {
"intermediate": 0.28304755687713623,
"beginner": 0.4412943720817566,
"expert": 0.2756580412387848
} |
19,311 | (((need also to update actual resizing on each new image. because it has a nice scale-up animation effect on initial preloading, but then it simply swithing in container statically. no, it sill swithing in container statically. any ideas how to rescale each consequencing image as on initial one? maybe there’s something else?
My apologies for the confusion. To achieve the desired scale-up animation effect for each subsequent image, you can modify the generateImage() function to clear the canvas and apply the animation effect before drawing the new image. One approach is to use JavaScript to manually animate the scaling of the canvas element.)))… again, it all out of synch simply! this css should depend on actual in javascript functionality when it senses that image is in array or something and normally applying all kinds of effect too it, without desynch.
the problem here is in actual animation time, because it don’t know when another image should arrive. the only method here is to store all recieved images in some array and sequentially apply all kinds of effects to them in an according ordered manner, without any problems with animation timings or relying on some css and else. : <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
function handleResize() {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.style.width = `${canvasWidth}px`;
canvas.style.height = `${canvasHeight}px`;
requestAnimationFrame(handleResize); // Continuously update aspect ratio
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | 8bab554dbd9acbfb5e184cc930962265 | {
"intermediate": 0.2985030710697174,
"beginner": 0.5970710515975952,
"expert": 0.10442589968442917
} |
19,312 | (((need also to update actual resizing on each new image. because it has a nice scale-up animation effect on initial preloading, but then it simply swithing in container statically. no, it sill swithing in container statically. any ideas how to rescale each consequencing image as on initial one? maybe there’s something else?
My apologies for the confusion. To achieve the desired scale-up animation effect for each subsequent image, you can modify the generateImage() function to clear the canvas and apply the animation effect before drawing the new image. One approach is to use JavaScript to manually animate the scaling of the canvas element.)))… again, it all out of synch simply! this css should depend on actual in javascript functionality when it senses that image is in array or something and normally applying all kinds of effect too it, without desynch.
the problem here is in actual animation time, because it don’t know when another image should arrive. the only method here is to store all recieved images in some array and sequentially apply all kinds of effects to them in an according ordered manner, without any problems with animation timings or relying on some css and else. : <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
function handleResize() {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.style.width = `${canvasWidth}px`;
canvas.style.height = `${canvasHeight}px`;
requestAnimationFrame(handleResize); // Continuously update aspect ratio
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | 358999ab92e1e68898477720c5c1321b | {
"intermediate": 0.2985030710697174,
"beginner": 0.5970710515975952,
"expert": 0.10442589968442917
} |
19,313 | (((need also to update actual resizing on each new image. because it has a nice scale-up animation effect on initial preloading, but then it simply swithing in container statically. no, it sill swithing in container statically. any ideas how to rescale each consequencing image as on initial one? maybe there’s something else?
My apologies for the confusion. To achieve the desired scale-up animation effect for each subsequent image, you can modify the generateImage() function to clear the canvas and apply the animation effect before drawing the new image. One approach is to use JavaScript to manually animate the scaling of the canvas element.)))… again, it all out of synch simply! this css should depend on actual in javascript functionality when it senses that image is in array or something and normally applying all kinds of effect too it, without desynch.
the problem here is in actual animation time, because it don’t know when another image should arrive. the only method here is to store all recieved images in some array and sequentially apply all kinds of effects to them in an according ordered manner, without any problems with animation timings or relying on some css and else. : <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
function handleResize() {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.style.width = `${canvasWidth}px`;
canvas.style.height = `${canvasHeight}px`;
requestAnimationFrame(handleResize); // Continuously update aspect ratio
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | e82af137b07a5735058d997f6214b2a8 | {
"intermediate": 0.2985030710697174,
"beginner": 0.5970710515975952,
"expert": 0.10442589968442917
} |
19,314 | (((need also to update actual resizing on each new image. because it has a nice scale-up animation effect on initial preloading, but then it simply swithing in container statically. no, it sill swithing in container statically. any ideas how to rescale each consequencing image as on initial one? maybe there’s something else?
My apologies for the confusion. To achieve the desired scale-up animation effect for each subsequent image, you can modify the generateImage() function to clear the canvas and apply the animation effect before drawing the new image. One approach is to use JavaScript to manually animate the scaling of the canvas element.)))… again, it all out of synch simply! this css should depend on actual in javascript functionality when it senses that image is in array or something and normally applying all kinds of effect too it, without desynch.
the problem here is in actual animation time, because it don’t know when another image should arrive. the only method here is to store all recieved images in some array and sequentially apply all kinds of effects to them in an according ordered manner, without any problems with animation timings or relying on some css and else. need an array method.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
function handleResize() {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.style.width = `${canvasWidth}px`;
canvas.style.height = `${canvasHeight}px`;
requestAnimationFrame(handleResize); // Continuously update aspect ratio
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | ee3837736e11bf0bf28c5fee8e9f8368 | {
"intermediate": 0.27938222885131836,
"beginner": 0.6159198880195618,
"expert": 0.1046978309750557
} |
19,315 | (((need also to update actual resizing on each new image. because it has a nice scale-up animation effect on initial preloading, but then it simply swithing in container statically. no, it sill swithing in container statically. any ideas how to rescale each consequencing image as on initial one? maybe there’s something else?
My apologies for the confusion. To achieve the desired scale-up animation effect for each subsequent image, you can modify the generateImage() function to clear the canvas and apply the animation effect before drawing the new image. One approach is to use JavaScript to manually animate the scaling of the canvas element.)))… again, it all out of synch simply! this css should depend on actual in javascript functionality when it senses that image is in array or something and normally applying all kinds of effect too it, without desynch.
the problem here is in actual animation time, because it don’t know when another image should arrive. the only method here is to store all recieved images in some array and sequentially apply all kinds of effects to them in an according ordered manner, without any problems with animation timings or relying on some css and else. need an array method!.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
function handleResize() {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.style.width = `${canvasWidth}px`;
canvas.style.height = `${canvasHeight}px`;
requestAnimationFrame(handleResize); // Continuously update aspect ratio
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | f022a2de4128664336751ae7ad21bf77 | {
"intermediate": 0.33296844363212585,
"beginner": 0.5672748684883118,
"expert": 0.09975659847259521
} |
19,316 | ok, I got a flickering problem in that "const receivedImages = [];", when each new image appears it flickers with some previous. I think it will be best to remove a each previous in sequance recieved image from the canvas and store it in some gallery array that we can then use to store a previous images in gallery and do whatever we want with them. try analize the code and apply what you think would be the best in that case.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas and apply animation effect
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha = 0;
const scaleUpAnimation = setInterval(function() {
if (ctx.globalAlpha >= 1) {
// Animation complete, draw the image
clearInterval(scaleUpAnimation);
ctx.globalAlpha = 1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
} else {
// Animation still in progress, gradually increase opacity
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha += 0.1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
}
}, 1000);
receivedImages.push(img); // Store the received image in the array
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
function handleResize() {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.style.width = `${canvasWidth}px`;
canvas.style.height = `${canvasHeight}px`;
requestAnimationFrame(handleResize); // Continuously update aspect ratio
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | 73364661be2fc9786e5ef29f72dd58c7 | {
"intermediate": 0.359839528799057,
"beginner": 0.28666457533836365,
"expert": 0.3534958064556122
} |
19,317 | hi | 07aee5b5aa3338d6b0701ddef987479e | {
"intermediate": 0.3246487081050873,
"beginner": 0.27135494351387024,
"expert": 0.40399640798568726
} |
19,318 | fix possible errors in these arrays. got some object overload error. output fixed asynch function.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
// Remove and clear previous images
for (const image of galleryImages) {
image.onload = null;
URL.revokeObjectURL(image.src);
}
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas and apply animation effect
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha = 0;
const scaleUpAnimation = setInterval(function() {
if (ctx.globalAlpha >= 1) {
// Animation complete, draw the image
clearInterval(scaleUpAnimation);
ctx.globalAlpha = 1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
} else {
// Animation still in progress, gradually increase opacity
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha += 0.1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
}
}, 1000);
// Remove the previous received image from receivedImages array
if (receivedImages.length > 0) {
const previousImage = receivedImages.shift();
galleryImages.push(previousImage);
}};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
function handleResize() {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.style.width = `${canvasWidth}px`;
canvas.style.height = `${canvasHeight}px`;
requestAnimationFrame(handleResize); // Continuously update aspect ratio
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | e6ac3bb658f47a67e3437a9e8f6bfda1 | {
"intermediate": 0.36719322204589844,
"beginner": 0.3990703523159027,
"expert": 0.23373642563819885
} |
19,319 | Please write a VBA code that can do the following:
In sheet 'Overtime' I want to select a range of cells in column C:C that have text values.
I would then like to find all matches in the selection that match the text value in sheet 'OTForm' cell B4.
For each cell value found in the selection range C:C in the the sheet 'Overtime' that matches the cell value B4 in sheet 'OTForm',
then starting from row 11 in sheet 'OTForm',
copy the row value in column 'A' in sheet 'Overtime' to column 'A' in sheet 'OTForm'
copy the row value in column 'D' in sheet 'Overtime' to column 'B' in sheet 'OTForm'
copy the row value in column 'AD' in sheet 'Overtime' to column 'C' in sheet 'OTForm'
copy the row value in column 'AE' in sheet 'Overtime' to column 'D' in sheet 'OTForm'
and continue this for all the matching values found in the range selection in C:C of sheet 'Overtime. | 17f0febb0c659b24e1fc96077c4e4bc0 | {
"intermediate": 0.4926239848136902,
"beginner": 0.18154555559158325,
"expert": 0.32583045959472656
} |
19,320 | ok, I got a flickering problem in that "const receivedImages = [];", when each new image appears it flickers with some previous. I think it will be best to remove a each previous in sequance recieved image from the canvas and store it in some gallery array that we can then use to store a previous images in gallery and do whatever we want with them. initially there’s no any images, because we are getting them remotely from that text2image AI backend. need to handle that situation and apply a countermeasure for such a nasty error. so, the idea for images array is purely to hande the problem with animation timings desynch, and gallery array in its case serves as an array for future unimplemented gallery that should potentially hold already recieved images and store them all in some appropriate fashion… try analize the code and apply what you think would be the best in that case.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas and apply animation effect
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha = 0;
const scaleUpAnimation = setInterval(function() {
if (ctx.globalAlpha >= 1) {
// Animation complete, draw the image
clearInterval(scaleUpAnimation);
ctx.globalAlpha = 1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
} else {
// Animation still in progress, gradually increase opacity
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha += 0.1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
}
}, 1000);
receivedImages.push(img); // Store the received image in the array
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
function handleResize() {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.style.width = `${canvasWidth}px`;
canvas.style.height = `${canvasHeight}px`;
requestAnimationFrame(handleResize); // Continuously update aspect ratio
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | e6d4d3809dab77b7e814a7a4e8cf9ef6 | {
"intermediate": 0.41131728887557983,
"beginner": 0.3035071790218353,
"expert": 0.2851755619049072
} |
19,321 | now there’s some slight overheat, due to some in loop miscalculations in arrays probably.
If you are experiencing performance issues with the code, it might be due to the continuous looping and redrawing of images in the handleResize() function. To optimize performance, you can make the following changes:
1. Add a flag isResizing to prevent multiple concurrent calls to the handleResize() function:
let isResizing = false;
2. Modify the handleResize() function to handle the resizing logic within a requestAnimationFrame() callback to debounce the function calls: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas and apply animation effect
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha = 0;
const scaleUpAnimation = setInterval(function() {
if (ctx.globalAlpha >= 1) {
// Animation complete, draw the image
clearInterval(scaleUpAnimation);
ctx.globalAlpha = 1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
} else {
// Animation still in progress, gradually increase opacity
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha += 0.1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
}
}, 1000);
if (receivedImages.length > 0) {
const previousImage = receivedImages.shift();
galleryArray.push(previousImage);
}
receivedImages.push(img); // Store the received image in the array
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
function handleResize() {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
requestAnimationFrame(handleResize);
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | 9c4b1345f60b8c0208c2cb34448c3d16 | {
"intermediate": 0.35097676515579224,
"beginner": 0.388457328081131,
"expert": 0.2605658769607544
} |
19,322 | ok, I got a flickering problem in that “const receivedImages = [];”, when each new image appears it flickers with some previous. I think it will be best to remove a each previous in sequance recieved image from the canvas and store it in some gallery array that we can then use to store a previous images in gallery and do whatever we want with them. initially there’s no any images, because we are getting them remotely from that text2image AI backend. need to handle that situation and apply a countermeasure for such a nasty error. so, the idea for images array is purely to hande the problem with animation timings desynch, and gallery array in its case serves as an array for future unimplemented gallery that should potentially hold already recieved images and store them all in some appropriate fashion… try analize the code and apply what you think would be the best in that case. now there’s some slight overheat, due to some in loop miscalculations in arrays probably.
If you are experiencing performance issues with the code, it might be due to the continuous looping and redrawing of images in the handleResize() function. try fix all errors and show what to change there.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas and apply animation effect
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha = 0;
const scaleUpAnimation = setInterval(function() {
if (ctx.globalAlpha >= 1) {
// Animation complete, draw the image
clearInterval(scaleUpAnimation);
ctx.globalAlpha = 1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
} else {
// Animation still in progress, gradually increase opacity
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha += 0.1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
}
}, 1000);
if (receivedImages.length > 0) {
const previousImage = receivedImages.shift();
galleryArray.push(previousImage);
}
receivedImages.push(img); // Store the received image in the array
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | 8a9da761f6df3b5032091ad810fc1b82 | {
"intermediate": 0.3220660984516144,
"beginner": 0.46592777967453003,
"expert": 0.21200616657733917
} |
19,323 | The code below works, but it is having some issues with the offset positioning. I have hidden columns in sheet 'OTForm'.
Can you provide an alternative to Offset in the copy event.
Sub CopyMatchingValues()
Dim OvertimeSheet As Worksheet
Dim OTFormSheet As Worksheet
Dim OvertimeRange As Range
Dim OTFormRange As Range
Dim OvertimeCell As Range
Dim OTFormCell As Range
Dim LastRow As Long
Dim i As Long
Set OvertimeSheet = ThisWorkbook.Sheets("Overtime")
On Error Resume Next
Set OvertimeRange = Application.InputBox("Select range in column C", Type:=8)
On Error GoTo 0
If OvertimeRange Is Nothing Or Not OvertimeRange.Columns(1).Column = 3 Then
MsgBox "No valid range selected in column C.", vbCritical
Exit Sub
End If
Set OTFormSheet = ThisWorkbook.Sheets("OTForm")
Set OTFormRange = OTFormSheet.Range("B4")
LastRow = 11
For Each OvertimeCell In OvertimeRange
If OvertimeCell.Value = OTFormRange.Value Then
OTFormSheet.Cells(LastRow, "A").Value = OvertimeCell.Offset(0, -2).Value
OTFormSheet.Cells(LastRow, "B").Value = OvertimeCell.Offset(0, 1).Value
OTFormSheet.Cells(LastRow, "C").Value = OvertimeCell.Offset(0, 16).Value
OTFormSheet.Cells(LastRow, "D").Value = OvertimeCell.Offset(0, 17).Value
LastRow = LastRow + 1
End If
Next OvertimeCell
End Sub | 060716dcf1fd8e964f536bb6d2c62caa | {
"intermediate": 0.5355909466743469,
"beginner": 0.31750550866127014,
"expert": 0.14690352976322174
} |
19,324 | ok, I got a flickering problem in that “const receivedImages = [];”, when each new image appears it flickers with some previous. I think it will be best to remove a each previous in sequance recieved image from the canvas and store it in some gallery array that we can then use to store a previous images in gallery and do whatever we want with them. initially there’s no any images, because we are getting them remotely from that text2image AI backend. need to handle that situation and apply a countermeasure for such a nasty error. so, the idea for images array is purely to hande the problem with animation timings desynch, and gallery array in its case serves as an array for future unimplemented gallery that should potentially hold already recieved images and store them all in some appropriate fashion… try analize the code and apply what you think would be the best in that case. now there’s some slight overheat, due to some in loop miscalculations in arrays probably.
If you are experiencing performance issues with the code, it might be due to the continuous looping and redrawing of images in the handleResize() function. try fix all errors and show what to change there.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas and apply animation effect
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha = 0;
const scaleUpAnimation = setInterval(function() {
if (ctx.globalAlpha >= 1) {
// Animation complete, draw the image
clearInterval(scaleUpAnimation);
ctx.globalAlpha = 1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
} else {
// Animation still in progress, gradually increase opacity
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha += 0.1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
}
}, 1000);
if (receivedImages.length > 0) {
const previousImage = receivedImages.shift();
galleryArray.push(previousImage);
}
receivedImages.push(img); // Store the received image in the array
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | b38f6c4c342dbd5bc532c10b0debf1a0 | {
"intermediate": 0.3220660984516144,
"beginner": 0.46592777967453003,
"expert": 0.21200616657733917
} |
19,325 | ok, I got a flickering problem in that “const receivedImages = [];”, when each new image appears it flickers with some previous. I think it will be best to remove a each previous in sequance recieved image from the canvas and store it in some gallery array that we can then use to store a previous images in gallery and do whatever we want with them. initially there’s no any images, because we are getting them remotely from that text2image AI backend. need to handle that situation and apply a countermeasure for such a nasty error. so, the idea for images array is purely to hande the problem with animation timings desynch, and gallery array in its case serves as an array for future unimplemented gallery that should potentially hold already recieved images and store them all in some appropriate fashion… try analize the code and apply what you think would be the best in that case. now there’s some slight overheat, due to some in loop miscalculations in arrays probably.
If you are experiencing performance issues with the code, it might be due to the continuous looping and redrawing of images in the handleResize() function. try show what to change there.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100%;
height: calc(100vw / 50vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
background-color: transparent;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas and apply animation effect
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha = 0;
const scaleUpAnimation = setInterval(function() {
if (ctx.globalAlpha >= 1) {
// Animation complete, draw the image
clearInterval(scaleUpAnimation);
ctx.globalAlpha = 1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
} else {
// Animation still in progress, gradually increase opacity
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha += 0.1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
}
}, 1000);
if (receivedImages.length > 0) {
const previousImage = receivedImages.shift();
galleryArray.push(previousImage);
}
receivedImages.push(img); // Store the received image in the array
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | 2f85d8a92062d254bfedf85040497c12 | {
"intermediate": 0.38080283999443054,
"beginner": 0.4148169457912445,
"expert": 0.20438021421432495
} |
19,326 | ok, I got a flickering problem in that “const receivedImages = [];”, when each new image appears it flickers with some previous. I think it will be best to remove a each previous in sequance recieved image from the canvas and store it in some gallery array that we can then use to store a previous images in gallery and do whatever we want with them. initially there’s no any images, because we are getting them remotely from that text2image AI backend. need to handle that situation and apply a countermeasure for such a nasty error. so, the idea for images array is purely to hande the problem with animation timings desynch, and gallery array in its case serves as an array for future unimplemented gallery that should potentially hold already recieved images and store them all in some appropriate fashion… try analize the code and apply what you think would be the best in that case. now there’s some slight overheat, due to some in loop miscalculations in arrays probably.
If you are experiencing performance issues with the code, it might be due to the continuous looping and redrawing of images in the handleResize() function. try show what to change there.: <html>
<head>
<title>Text2Image AI</title>
<style>
//fuck you gpt context-length!
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas and apply animation effect
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha = 0;
const scaleUpAnimation = setInterval(function() {
if (ctx.globalAlpha >= 1) {
// Animation complete, draw the image
clearInterval(scaleUpAnimation);
ctx.globalAlpha = 1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
} else {
// Animation still in progress, gradually increase opacity
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha += 0.1;
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
}
}, 1000);
if (receivedImages.length > 0) {
const previousImage = receivedImages.shift();
galleryArray.push(previousImage);
}
receivedImages.push(img); // Store the received image in the array
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | e12f2535ae44c827db5a02c33609b260 | {
"intermediate": 0.43028703331947327,
"beginner": 0.3606378138065338,
"expert": 0.20907513797283173
} |
19,327 | ok, I got a flickering problem in that “const receivedImages = [];”, when each new image appears it flickers with some previous. I think it will be best to remove a each previous in sequance recieved image from the canvas and store it in some gallery array that we can then use to store a previous images in gallery and do whatever we want with them. initially there’s no any images, because we are getting them remotely from that text2image AI backend. need to handle that situation and apply a countermeasure for such a nasty error. so, the idea for images array is purely to hande the problem with animation timings desynch, and gallery array in its case serves as an array for future unimplemented gallery that should potentially hold already recieved images and store them all in some appropriate fashion… try analize the code and apply what you think would be the best in that case. now there’s some slight overheat, due to some in loop miscalculations in arrays probably.
If you are experiencing performance issues with the code, it might be due to the continuous looping and redrawing of images in the handleResize() function. try show what to change there. the problem most likely due to some windom updatings in resizing, because when you manually resize the window, the flickering images disappears.: <html>
<head>
<title>Text2Image AI</title>
<style>
//no context-length for this shit left.
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha = 0;
const scaleUpAnimation = setInterval(function () {
if (ctx.globalAlpha >= 1) {
// Animation complete, draw the image and clear the interval
clearInterval(scaleUpAnimation);
ctx.globalAlpha = 1;
ctx.clearRect(0, 0, canvasWidth, canvasHeight); // Clear canvas before drawing the image
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
} else {
// Animation still in progress, gradually increase opacity
ctx.globalAlpha += 0.05; // Adjust the increment value for a smoother transition
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
}
}, 50); // Adjust the interval timing for a smoother animation
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | 9aa8cd4318aa999f2c59e531918813d6 | {
"intermediate": 0.4672313928604126,
"beginner": 0.3264862895011902,
"expert": 0.20628228783607483
} |
19,328 | how do I clear this variable from memory: Private activeCellRange As Range | 60f7e89fea67cc43102e482612c896b9 | {
"intermediate": 0.3602605164051056,
"beginner": 0.4548625349998474,
"expert": 0.184876948595047
} |
19,329 | in x86 asm make a program that sends a udp packet to 1.1.1.1 | c55fb97c4433042e29ef05797def2291 | {
"intermediate": 0.4074265658855438,
"beginner": 0.20251338183879852,
"expert": 0.39006003737449646
} |
19,330 | Привет, как мне сделать проверку от обратного в waitForCloseMenu используя метод waitForCloseMenu
def waitForOpenMenu(self, timeout = 3000):
qml.findObjectExists(self.names, timeout)
def waitForCloseMenu(self, timeout = 2000):
try:
squish.waitFor('not object.exists(self.names)', timeout)
except LookupError:
test.warning(f'Объект {name} не пропал после истечения таймаута') | b9095dcc2c6a042475e836c2a2d4a604 | {
"intermediate": 0.37421292066574097,
"beginner": 0.3246390223503113,
"expert": 0.30114805698394775
} |
19,331 | ok, I got a flickering problem in that “const receivedImages = [];”, when each new image appears it flickers with some previous. I think it will be best to remove a each previous in sequance recieved image from the canvas and store it in some gallery array that we can then use to store a previous images in gallery and do whatever we want with them. initially there’s no any images, because we are getting them remotely from that text2image AI backend. need to handle that situation and apply a countermeasure for such a nasty error. so, the idea for images array is purely to hande the problem with animation timings desynch, and gallery array in its case serves as an array for future unimplemented gallery that should potentially hold already recieved images and store them all in some appropriate fashion… try analize the code and apply what you think would be the best in that case. now there’s some slight overheat, due to some in loop miscalculations in arrays probably.
If you are experiencing performance issues with the code, it might be due to the continuous looping and redrawing of images in the handleResize() function. try show what to change there. the problem most likely due to some windom updatings in resizing, because when you manually resize the window, the flickering images disappears.: <html>
<head>
<title>Text2Image AI</title>
<style>
//no context-length for this shit left.
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const receivedImages = [];
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.globalAlpha = 0;
const scaleUpAnimation = setInterval(function () {
if (ctx.globalAlpha >= 1) {
// Animation complete, draw the image and clear the interval
clearInterval(scaleUpAnimation);
ctx.globalAlpha = 1;
ctx.clearRect(0, 0, canvasWidth, canvasHeight); // Clear canvas before drawing the image
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
} else {
// Animation still in progress, gradually increase opacity
ctx.globalAlpha += 0.05; // Adjust the increment value for a smoother transition
ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
}
}, 50); // Adjust the interval timing for a smoother animation
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | 5509dc4bdf14c9cdcb2672f8b27c77dd | {
"intermediate": 0.4672313928604126,
"beginner": 0.3264862895011902,
"expert": 0.20628228783607483
} |
19,332 | Hello! | a0fa3ff44b4cddfc9bb85222f06e234e | {
"intermediate": 0.3194829821586609,
"beginner": 0.26423266530036926,
"expert": 0.41628435254096985
} |
19,333 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | 41bbbf895e6f4a9ba8fffd2372ab185b | {
"intermediate": 0.31506016850471497,
"beginner": 0.3315625786781311,
"expert": 0.3533773124217987
} |
19,334 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible.: <html>
<head>
<title>Text2Image AI</title>
<style>
fuck gpt!
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
});
</script>
</body>
</html> | 561092b69c70daa39eef31fd20a39fb1 | {
"intermediate": 0.339596688747406,
"beginner": 0.48330414295196533,
"expert": 0.17709916830062866
} |
19,335 | A college website home page code using asp.net | c10868b1a9905fbdd2a67f7d01aa0fb9 | {
"intermediate": 0.31844568252563477,
"beginner": 0.2771261930465698,
"expert": 0.4044281840324402
} |
19,336 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 0d23ebfd9876117d6a00ba4a49a6644a | {
"intermediate": 0.3662315905094147,
"beginner": 0.40298932790756226,
"expert": 0.23077909648418427
} |
19,337 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | c627d3ee0980d7cd6aa80ef7bc6aeb11 | {
"intermediate": 0.3662315905094147,
"beginner": 0.40298932790756226,
"expert": 0.23077909648418427
} |
19,338 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | c4cfe35752363cbfd398aed128913e7b | {
"intermediate": 0.3662315905094147,
"beginner": 0.40298932790756226,
"expert": 0.23077909648418427
} |
19,339 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | b2be89b6d42dc855f76cb0aeb197d482 | {
"intermediate": 0.48548823595046997,
"beginner": 0.3552702069282532,
"expert": 0.15924158692359924
} |
19,340 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. output fully fixed javascript only fixed: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | cd8b262016eda073bebe53ac296055e4 | {
"intermediate": 0.4327850639820099,
"beginner": 0.37677955627441406,
"expert": 0.19043536484241486
} |
19,341 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. output fully fixed javascript only fixed: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | bf35f72f45fde8c1eb71c8d31332f9ab | {
"intermediate": 0.4327850639820099,
"beginner": 0.37677955627441406,
"expert": 0.19043536484241486
} |
19,342 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. output fully fixed javascript only fixed: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 697091bd1b33d9db409228cbaa7e66f9 | {
"intermediate": 0.4327850639820099,
"beginner": 0.37677955627441406,
"expert": 0.19043536484241486
} |
19,343 | Is it possible to use hardware uuid from dmidecode like passphrase for a root luks encrypted partition and then use dmidecode while the boot with initramfs in order to unencrypt the luks root partition and automatically boot ?
If it's possible show me. | 5bf4bc4cc7d6c25dbc9d8628db9ce2b2 | {
"intermediate": 0.3940598666667938,
"beginner": 0.14189325273036957,
"expert": 0.464046835899353
} |
19,344 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. output fully fixed javascript only fixed: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 023135a1259e169f065281e27ee38aeb | {
"intermediate": 0.4327850639820099,
"beginner": 0.37677955627441406,
"expert": 0.19043536484241486
} |
19,345 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. output fully fixed javascript only fixed: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 6fd57e052198908bea4f55f1caddedeb | {
"intermediate": 0.4327850639820099,
"beginner": 0.37677955627441406,
"expert": 0.19043536484241486
} |
19,346 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. output fully fixed javascript only fixed: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 722f037ec0cc4e98fe9b00fead5a272a | {
"intermediate": 0.4327850639820099,
"beginner": 0.37677955627441406,
"expert": 0.19043536484241486
} |
19,347 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. output fully fixed javascript only fixed: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 1a6c98dcfc28fdef5cfc86008fd83360 | {
"intermediate": 0.4327850639820099,
"beginner": 0.37677955627441406,
"expert": 0.19043536484241486
} |
19,348 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. output fully fixed javascript only fixed: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | a61cf9bd3cf9c7500d97a06451272a1e | {
"intermediate": 0.4327850639820099,
"beginner": 0.37677955627441406,
"expert": 0.19043536484241486
} |
19,349 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. output fully fixed javascript only fixed: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 70ea25ddb663064a1a941cb0a41e3df5 | {
"intermediate": 0.4327850639820099,
"beginner": 0.37677955627441406,
"expert": 0.19043536484241486
} |
19,350 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 37023303889b9092fa88f2ace7d175b5 | {
"intermediate": 0.4795295298099518,
"beginner": 0.3272220194339752,
"expert": 0.19324848055839539
} |
19,351 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | a9da0bcd31eb670a98c9b030a811d1ef | {
"intermediate": 0.4795295298099518,
"beginner": 0.3272220194339752,
"expert": 0.19324848055839539
} |
19,352 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | f6d059cfc8cbf303635931ba76de5a74 | {
"intermediate": 0.4795295298099518,
"beginner": 0.3272220194339752,
"expert": 0.19324848055839539
} |
19,353 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 392261be26b8056cefb74cadc55bb1ea | {
"intermediate": 0.4795295298099518,
"beginner": 0.3272220194339752,
"expert": 0.19324848055839539
} |
19,354 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | b4c377d7cc6d8ca7c64a59647fb53455 | {
"intermediate": 0.4795295298099518,
"beginner": 0.3272220194339752,
"expert": 0.19324848055839539
} |
19,355 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | c3bfbbc59a77c678a3c0ad2fe007ce07 | {
"intermediate": 0.4795295298099518,
"beginner": 0.3272220194339752,
"expert": 0.19324848055839539
} |
19,356 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 8727b6b860e9b95541879d49a16fd4d9 | {
"intermediate": 0.4795295298099518,
"beginner": 0.3272220194339752,
"expert": 0.19324848055839539
} |
19,357 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 97b564790394580a10eef20c96c23804 | {
"intermediate": 0.4795295298099518,
"beginner": 0.3272220194339752,
"expert": 0.19324848055839539
} |
19,358 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 0981d00fd4ad5396db49e782d913a7d4 | {
"intermediate": 0.4795295298099518,
"beginner": 0.3272220194339752,
"expert": 0.19324848055839539
} |
19,359 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 1b9a27d1d53e084907134711b42a7e1d | {
"intermediate": 0.4795295298099518,
"beginner": 0.3272220194339752,
"expert": 0.19324848055839539
} |
19,360 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | d73bf2f1535cb723c99093e03a0f16f6 | {
"intermediate": 0.4795295298099518,
"beginner": 0.3272220194339752,
"expert": 0.19324848055839539
} |
19,361 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed just javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 09108805eef20a4371d293dfe1c7be81 | {
"intermediate": 0.5129329562187195,
"beginner": 0.3293231725692749,
"expert": 0.1577438861131668
} |
19,362 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed just javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 73ae86915e4cacb3d5fc4c108efca36e | {
"intermediate": 0.5129329562187195,
"beginner": 0.3293231725692749,
"expert": 0.1577438861131668
} |
19,363 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed just javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 12c47fafe34537b7e5a469aa48a1291b | {
"intermediate": 0.5129329562187195,
"beginner": 0.3293231725692749,
"expert": 0.1577438861131668
} |
19,364 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed just javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | c38ccc7fdcbab97b092332a21d7c0147 | {
"intermediate": 0.5129329562187195,
"beginner": 0.3293231725692749,
"expert": 0.1577438861131668
} |
19,365 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed just javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | b3e2dbb0a05ac7ba4782a0c8a8a987bd | {
"intermediate": 0.5129329562187195,
"beginner": 0.3293231725692749,
"expert": 0.1577438861131668
} |
19,366 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed just javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 44059df2fb21c41fd8638ca02857fb59 | {
"intermediate": 0.5129329562187195,
"beginner": 0.3293231725692749,
"expert": 0.1577438861131668
} |
19,367 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed just javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 282f5a7be77de2ccefc26f44228916f4 | {
"intermediate": 0.5129329562187195,
"beginner": 0.3293231725692749,
"expert": 0.1577438861131668
} |
19,368 | now you need to resize the window manually to update initial image appeared from that text2image AI backend, sinceverse its invisible. here’s how it wrongly works now: initially you genning an image and nothing visible, until you manually by hand resize that window size and only then it triggers an update to canvas and image appears. need to fix that issue by not ruinning the rest of functionality.nope. the image seems to be expanding the canvas or ‘canvas-container’ but nothing visible still. it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed just javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | f834f78a0a5d0c963b6c2211a10b3e1e | {
"intermediate": 0.5129329562187195,
"beginner": 0.3293231725692749,
"expert": 0.1577438861131668
} |
19,369 | it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed just javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | e6fb682e2380ece2d4d6cf43b6404739 | {
"intermediate": 0.31220489740371704,
"beginner": 0.4700610637664795,
"expert": 0.21773402392864227
} |
19,370 | it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed just javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 7e5b45e89f868cade3eacd283f4b551b | {
"intermediate": 0.31220489740371704,
"beginner": 0.4700610637664795,
"expert": 0.21773402392864227
} |
19,371 | it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed just javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 743d6c3aa48867f0d4fb282c9c69fa53 | {
"intermediate": 0.31220489740371704,
"beginner": 0.4700610637664795,
"expert": 0.21773402392864227
} |
19,372 | what google sheets formula will give me the number of next month | 84e496ddfc667050f7fac3ceb7fae990 | {
"intermediate": 0.30374249815940857,
"beginner": 0.2452618032693863,
"expert": 0.45099568367004395
} |
19,373 | it only updates the image on canvas when some window interferencing event triggers it. no, the same static nothingness in canvascontainer. need to look on that fetching mechanism, when we getting an image from backend and placing it in our canvas. it seems the only way to actually update an image is to trigger some dummy onanimation update on canvas from initial generation, when we get an image, and after some periodic time.output fully fixed just javascript only fixed.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
const img = new Image();
img.onload = function() {
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 1131f53e0520965755ce7d4208aa2dd9 | {
"intermediate": 0.31220489740371704,
"beginner": 0.4700610637664795,
"expert": 0.21773402392864227
} |
19,374 | add a button somewhere that popups the gallery window on full window size and shows these images in gallery array that was previously stored from that text2image AI backend. can you? show only code that need to be added or modified.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | ad374270e5b200114c28cb7ccaff4c49 | {
"intermediate": 0.30673566460609436,
"beginner": 0.44851213693618774,
"expert": 0.2447522133588791
} |
19,375 | add a button somewhere that popups the gallery window on full window size and shows these images in gallery array that was previously stored from that text2image AI backend. can you? show only code that need to be added or modified.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 826e9b85bdde4ccc3ba4427a25784cf0 | {
"intermediate": 0.30673566460609436,
"beginner": 0.44851213693618774,
"expert": 0.2447522133588791
} |
19,376 | add a button somewhere that popups the gallery window on full window size and shows these images in gallery array that was previously stored from that text2image AI backend. can you? show only code that need to be added or modified.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | e4a7dc37bba02cfbde2f84740aa0bdf9 | {
"intermediate": 0.30673566460609436,
"beginner": 0.44851213693618774,
"expert": 0.2447522133588791
} |
19,377 | need to fix that gallery to keep stored images in an aligned manner to fill gallery modal progressively from that gallery array. also, need probably a different approach here. output only what need to modify or add.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<button onclick='openGallery()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Open Gallery</button>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<div id='galleryModal' class='modal'>
<span class='close' onclick='closeGallery()'>×</span>
<div class='modal-content'>
<div class='canvas-container'>
<canvas id='galleryCanvas' class='image-canvas'></canvas>
</div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
// Function to open the gallery window
function openGallery() {
const galleryModal = document.getElementById('galleryModal');
const galleryCanvas = document.getElementById('galleryCanvas');
galleryModal.style.display = 'block';
// Clear the canvas before drawing the images
const ctx = galleryCanvas.getContext('2d');
ctx.clearRect(0, 0, galleryCanvas.width, galleryCanvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const aspectRatio = image.width / image.height;
let canvasWidth = galleryCanvas.width;
let canvasHeight = galleryCanvas.width / aspectRatio;
if (canvasHeight > galleryCanvas.height) {
canvasHeight = galleryCanvas.height;
canvasWidth = galleryCanvas.height * aspectRatio;
}
const x = (galleryCanvas.width - canvasWidth) / 2;
const y = (galleryCanvas.height - canvasHeight) / 2;
ctx.drawImage(image, x, y, canvasWidth, canvasHeight);
});
}
// Function to close the gallery window
function closeGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 2d45b732bd8ff75aad103f81f58129bc | {
"intermediate": 0.3526647686958313,
"beginner": 0.40886735916137695,
"expert": 0.23846784234046936
} |
19,378 | need to fix that gallery to keep stored images in an aligned manner to fill gallery modal progressively from that gallery array. also, need probably a different approach here. output only what need to modify or add.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<button onclick='openGallery()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Open Gallery</button>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<div id='galleryModal' class='modal'>
<span class='close' onclick='closeGallery()'>×</span>
<div class='modal-content'>
<div class='canvas-container'>
<canvas id='galleryCanvas' class='image-canvas'></canvas>
</div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
// Function to open the gallery window
function openGallery() {
const galleryModal = document.getElementById('galleryModal');
const galleryCanvas = document.getElementById('galleryCanvas');
galleryModal.style.display = 'block';
// Clear the canvas before drawing the images
const ctx = galleryCanvas.getContext('2d');
ctx.clearRect(0, 0, galleryCanvas.width, galleryCanvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const aspectRatio = image.width / image.height;
let canvasWidth = galleryCanvas.width;
let canvasHeight = galleryCanvas.width / aspectRatio;
if (canvasHeight > galleryCanvas.height) {
canvasHeight = galleryCanvas.height;
canvasWidth = galleryCanvas.height * aspectRatio;
}
const x = (galleryCanvas.width - canvasWidth) / 2;
const y = (galleryCanvas.height - canvasHeight) / 2;
ctx.drawImage(image, x, y, canvasWidth, canvasHeight);
});
}
// Function to close the gallery window
function closeGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 7f67dd06e28136395847075984c379b9 | {
"intermediate": 0.3526647686958313,
"beginner": 0.40886735916137695,
"expert": 0.23846784234046936
} |
19,379 | need to fix that gallery to keep stored images in an aligned manner to fill gallery modal progressively from that gallery array. also, need probably a different approach here. output only what need to modify or add.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<button onclick='openGallery()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Open Gallery</button>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<div id='galleryModal' class='modal'>
<span class='close' onclick='closeGallery()'>×</span>
<div class='modal-content'>
<div class='canvas-container'>
<canvas id='galleryCanvas' class='image-canvas'></canvas>
</div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
// Function to open the gallery window
function openGallery() {
const galleryModal = document.getElementById('galleryModal');
const galleryCanvas = document.getElementById('galleryCanvas');
galleryModal.style.display = 'block';
// Clear the canvas before drawing the images
const ctx = galleryCanvas.getContext('2d');
ctx.clearRect(0, 0, galleryCanvas.width, galleryCanvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const aspectRatio = image.width / image.height;
let canvasWidth = galleryCanvas.width;
let canvasHeight = galleryCanvas.width / aspectRatio;
if (canvasHeight > galleryCanvas.height) {
canvasHeight = galleryCanvas.height;
canvasWidth = galleryCanvas.height * aspectRatio;
}
const x = (galleryCanvas.width - canvasWidth) / 2;
const y = (galleryCanvas.height - canvasHeight) / 2;
ctx.drawImage(image, x, y, canvasWidth, canvasHeight);
});
}
// Function to close the gallery window
function closeGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | bd74a36b5c55e75b49d99aa69935a53f | {
"intermediate": 0.3526647686958313,
"beginner": 0.40886735916137695,
"expert": 0.23846784234046936
} |
19,380 | in typescript how do i make a tuple type, where each element is of my generic type | 936fbc706ab52c616279038f31781906 | {
"intermediate": 0.40705224871635437,
"beginner": 0.34008705615997314,
"expert": 0.2528606951236725
} |
19,381 | in typescript, if i have a tuple as a generic argument, how can i get the literal type of an element of that tuple? | 22b2b675b7d9f34b6eb87d9753c4698b | {
"intermediate": 0.43563133478164673,
"beginner": 0.3027644157409668,
"expert": 0.26160427927970886
} |
19,382 | current gallery shows only actual image recieved from that backend text2image inside at the center without updating, while gallery window should auto-store all previous images comed from backend and auto-updatingly align them in auto-flexible inline-grid fashion or something. output only what need to modify or add.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.gallery-canvas-container {
position: relative;
width: 100%;
display:inline-grid;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<button onclick='openGallery()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Open Gallery</button>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<div id='galleryModal' class='modal'>
<span class='close' onclick='closeGallery()'>×</span>
<div class='modal-content'>
<div class='gallery-canvas-container'>
<canvas id='galleryCanvas' class='image-canvas'></canvas>
</div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
function openGallery() {
const galleryModal = document.getElementById('galleryModal');
const galleryCanvas = document.getElementById('galleryCanvas');
galleryModal.style.display = 'block';
// Clear the canvas before drawing the images
const ctx = galleryCanvas.getContext('2d');
ctx.clearRect(0, 0, galleryCanvas.width, galleryCanvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const aspectRatio = image.width / image.height;
let canvasWidth = galleryCanvas.width;
let canvasHeight = galleryCanvas.width / aspectRatio;
if (canvasHeight > galleryCanvas.height) {
canvasHeight = galleryCanvas.height;
canvasWidth = galleryCanvas.height * aspectRatio;
}
const x = (galleryCanvas.width - canvasWidth) / 2;
const y = (galleryCanvas.height - canvasHeight) / 2;
ctx.drawImage(image, x, y, canvasWidth, canvasHeight);
});
}
// Function to close the gallery window
function closeGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 25ca6c59f2ac153d6b7cb344bad04997 | {
"intermediate": 0.2592281997203827,
"beginner": 0.4358641505241394,
"expert": 0.3049076497554779
} |
19,383 | can you optimize this code and reduce it in lines of actual code, without ruinning functionality?: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<button onclick='openGallery()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Open Gallery</button>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<div id='galleryModal' class='modal'>
<span class='close' onclick='closeGallery()'>×</span>
<div class='modal-content'>
<div class='gallery-canvas-container'>
<canvas id='galleryCanvas' class='image-canvas'></canvas>
</div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
function openGallery() {
const galleryModal = document.getElementById('galleryModal');
const galleryCanvas = document.getElementById('galleryCanvas');
galleryModal.style.display = 'block';
// Clear the canvas before drawing the images
const ctx = galleryCanvas.getContext('2d');
ctx.clearRect(0, 0, galleryCanvas.width, galleryCanvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const aspectRatio = image.width / image.height;
let canvasWidth = galleryCanvas.width;
let canvasHeight = galleryCanvas.width / aspectRatio;
if (canvasHeight > galleryCanvas.height) {
canvasHeight = galleryCanvas.height;
canvasWidth = galleryCanvas.height * aspectRatio;
}
const x = (galleryCanvas.width - canvasWidth) / 2;
const y = (galleryCanvas.height - canvasHeight) / 2;
ctx.drawImage(image, x, y, canvasWidth, canvasHeight);
});
}
// Function to close the gallery window
function closeGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 94aa3de983b74d3ee38ae967ac43149c | {
"intermediate": 0.361453115940094,
"beginner": 0.3625532388687134,
"expert": 0.275993674993515
} |
19,384 | try optimize javascript only by combining eveything and recombining etc. reduce in actual lines of code but without ruinning functionality.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<button onclick='openGallery()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Open Gallery</button>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<div id='galleryModal' class='modal'>
<span class='close' onclick='closeGallery()'>×</span>
<div class='modal-content'>
<div class='gallery-canvas-container'>
<canvas id='galleryCanvas' class='image-canvas'></canvas>
</div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
let generateInterval;
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(function() {
generateImage();
}, timeout);
generateInterval = setInterval(function() {
generateImage();
}, interval);
}
}
const galleryArray = [];
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(function () {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
const imageWidth = img.naturalWidth;
const imageHeight = img.naturalHeight;
const aspectRatio = img.width / img.height;
const containerWidth = imageCanvas.parentElement.clientWidth; // Get the width of the container
const containerHeight = imageCanvas.parentElement.clientHeight; // Get the height of the container
const minAvailableWidth = containerWidth;
const maxAvailableHeight = containerHeight;
let canvasWidth = containerWidth;
let canvasHeight = maxAvailableHeight;
if (aspectRatio > 1) {
// Landscape image, fit width
canvasWidth = containerWidth;
canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > maxAvailableHeight) {
canvasHeight = maxAvailableHeight;
canvasWidth = canvasHeight * aspectRatio;
}
} else {
// Portrait or square image, fit height
canvasWidth = maxAvailableHeight * aspectRatio;
canvasHeight = maxAvailableHeight;
if (canvasWidth > containerWidth) {
canvasWidth = containerWidth;
canvasHeight = canvasWidth / aspectRatio;
}
}
imageCanvas.width = canvasWidth;
imageCanvas.height = canvasHeight;
// Clear canvas before starting the animation loop
const canvas = document.getElementById('imageCanvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
galleryArray.push(img);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
window.addEventListener('resize', handleResize);
let isResizing = false;
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const imageWidth = image.naturalWidth;
const imageHeight = image.naturalHeight;
const aspectRatio = imageWidth / imageHeight;
let canvasImageWidth = canvasWidth;
let canvasImageHeight = canvasWidth / aspectRatio;
if (canvasImageHeight > canvasHeight) {
canvasImageHeight = canvasHeight;
canvasImageWidth = canvasHeight * aspectRatio;
}
const x = (canvas.width - canvasImageWidth) / 2;
const y = (canvas.height - canvasImageHeight) / 2;
ctx.drawImage(image, x, y, canvasImageWidth, canvasImageHeight);
});
isResizing = false;
});
}
function openGallery() {
const galleryModal = document.getElementById('galleryModal');
const galleryCanvas = document.getElementById('galleryCanvas');
galleryModal.style.display = 'block';
// Clear the canvas before drawing the images
const ctx = galleryCanvas.getContext('2d');
ctx.clearRect(0, 0, galleryCanvas.width, galleryCanvas.height);
// Draw each image in the gallery array
galleryArray.forEach((image) => {
const aspectRatio = image.width / image.height;
let canvasWidth = galleryCanvas.width;
let canvasHeight = galleryCanvas.width / aspectRatio;
if (canvasHeight > galleryCanvas.height) {
canvasHeight = galleryCanvas.height;
canvasWidth = galleryCanvas.height * aspectRatio;
}
const x = (galleryCanvas.width - canvasWidth) / 2;
const y = (galleryCanvas.height - canvasHeight) / 2;
ctx.drawImage(image, x, y, canvasWidth, canvasHeight);
});
}
// Function to close the gallery window
function closeGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
</script>
</body>
</html> | 75c50476fb343ceba249f8ac7b80f0a2 | {
"intermediate": 0.3750355541706085,
"beginner": 0.3343234658241272,
"expert": 0.29064100980758667
} |
19,385 | .lala{
margin: 20px;
width: 2000px;
background-color: greenyellow;
display:grid;
grid-template-columns: repeat(Auto-fill ,minmax(100px,200px));
}
.sa {
background-color: coral;
}
.lala div {
background-color:blue;
}
why auto-fill doesn't work | d1814125a069594db98231ffbdb90667 | {
"intermediate": 0.41331884264945984,
"beginner": 0.3317504823207855,
"expert": 0.25493067502975464
} |
19,386 | TR1:=MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));
UP:=(HIGH+LOW)/2+MA(TR1,19)*2;
DN:=(HIGH+LOW)/2-MA(TR1,19)*2;
L1:=REF(UP,BARSLAST(UP<=REF(UP,1)));
L2:=LLV(UP,N*1.5);
LL:=IF(L2!=REF(L2,1) AND L1<REF(L1,1),L1,IF(L1=L2,L1,L2));
S1:=BARSLAST(CROSS(0.5,UP=LL))+1;
S2:=CROSS(COUNT((CROSS(C,LL) OR CROSS(C,REF(LL,2))) AND UP>LL,S1),0.5);
A6:=BARSLAST(S2);
B6:=BARSLAST(CROSS(HHV(DN,A6+1),C));
BY:=CROSS(B6,A6);
SL:=CROSS(A6,B6);
BARSLAST表示上次成立到当前的周期数,从通达信语言改成python | f603f5d111d83a6b400bfbc47d26b94a | {
"intermediate": 0.3562573194503784,
"beginner": 0.32217273116111755,
"expert": 0.32156991958618164
} |
19,387 | current gallery shows only actual image recieved from that backend text2image inside at the center without updating, while gallery window should auto-store all previous images comed from backend and auto-updatingly align them in auto-flexible inline-grid fashion or something. output only what need to modify or add.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<button onclick='openGallery()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Open Gallery</button>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<div id='galleryModal' class='modal'>
<span class='close' onclick='closeGallery()'>×</span>
<div class='modal-content'>
<div class='gallery-canvas-container'>
<canvas id='galleryCanvas' class='image-canvas'></canvas>
</div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const galleryArray = [];
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
let generateInterval;
let isResizing = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(() => {
generateImage();
}, timeout);
generateInterval = setInterval(() => {
generateImage();
}, interval);
}
}
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(() => {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
drawGalleryImages(imageCanvas);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawGalleryImages(canvas);
isResizing = false;
});
}
function drawGalleryImages(canvas) {
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const aspectRatio = image.width / image.height;
let canvasWidth = canvas.width;
let canvasHeight = canvas.width / aspectRatio;
if (canvasHeight > canvas.height) {
canvasHeight = canvas.height;
canvasWidth = canvas.height * aspectRatio;
}
const x = (canvas.width - canvasWidth) / 2;
const y = (canvas.height - canvasHeight) / 2;
ctx.drawImage(image, x, y, canvasWidth, canvasHeight);
});
}
function openGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'block';
drawGalleryImages(galleryCanvas);
}
function closeGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
window.addEventListener('resize', handleResize);
</script>
</body>
</html> | 42d127d5c5f21c7195eb865dd7f20239 | {
"intermediate": 0.20803910493850708,
"beginner": 0.4520977735519409,
"expert": 0.3398631811141968
} |
19,388 | current gallery shows only actual image recieved from that backend text2image inside at the center without updating, while gallery window should auto-store all previous images comed from backend and auto-updatingly align them in auto-flexible inline-grid fashion or something. output only what need to modify or add.: <html>
<head>
<title>Text2Image AI</title>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<button onclick='openGallery()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Open Gallery</button>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<div id='galleryModal' class='modal'>
<span class='close' onclick='closeGallery()'>×</span>
<div class='modal-content'>
<div class='gallery-canvas-container'>
<canvas id='galleryCanvas' class='image-canvas'></canvas>
</div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const galleryArray = [];
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
let generateInterval;
let isResizing = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(() => {
generateImage();
}, timeout);
generateInterval = setInterval(() => {
generateImage();
}, interval);
}
}
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(() => {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
drawGalleryImages(imageCanvas);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawGalleryImages(canvas);
isResizing = false;
});
}
function drawGalleryImages(canvas) {
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
galleryArray.forEach((image) => {
const aspectRatio = image.width / image.height;
let canvasWidth = canvas.width;
let canvasHeight = canvas.width / aspectRatio;
if (canvasHeight > canvas.height) {
canvasHeight = canvas.height;
canvasWidth = canvas.height * aspectRatio;
}
const x = (canvas.width - canvasWidth) / 2;
const y = (canvas.height - canvasHeight) / 2;
ctx.drawImage(image, x, y, canvasWidth, canvasHeight);
});
}
function openGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'block';
drawGalleryImages(galleryCanvas);
}
function closeGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
window.addEventListener('resize', handleResize);
</script>
</body>
</html> | 3073a2b293b798b98d9b4f34954b8aca | {
"intermediate": 0.20803910493850708,
"beginner": 0.4520977735519409,
"expert": 0.3398631811141968
} |
19,389 | Wirte poem about adam | b11524aa815f104e8fcd59b08f2845dd | {
"intermediate": 0.37192824482917786,
"beginner": 0.3269900977611542,
"expert": 0.30108165740966797
} |
19,390 | something wrong here. the images got recieved from backend are not properly aligned. the "<canvas id='imageCanvas' class='image-canvas'></canvas>" is for the main current output, while gallery should contain only previous images properly and endlessly aligned and auto-fitted strictly only withing gallery container, not the main canvas output. now everything is mixed there. don't know what to do. only show what need to modify or add.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.modal-content {
display: flex;
flex-wrap: wrap;
}
.gallery-canvas-container {
position: relative;
width: 100%;
display:inline-grid;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
flex-grow: 1;
margin-right: 10px;
}
#galleryCanvas {
width: 100%;
height: 100%;
}
.gallery-image {
margin: 5px;
max-height: 100px;
max-width: 100px;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<button onclick='openGallery()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Open Gallery</button>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<div id='galleryModal' class='modal'>
<span class='close' onclick='closeGallery()'>×</span>
<div class='modal-content'>
<div class='gallery-canvas-container'>
<canvas id='galleryCanvas' class='image-canvas'></canvas>
</div>
<div class='gallery-images-container'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const galleryArray = [];
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
let generateInterval;
let isResizing = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(() => {
generateImage();
}, timeout);
generateInterval = setInterval(() => {
generateImage();
}, interval);
}
}
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(() => {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
drawGalleryImages(imageCanvas);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawGalleryImages(canvas);
isResizing = false;
});
}
function drawGalleryImages(canvas) {
const ctx = canvas.getContext('2d');
const galleryImagesContainer = document.querySelector('.gallery-images-container');
galleryImagesContainer.innerHTML = ''; // Clear previous images
galleryArray.forEach((image) => {
const img = document.createElement('img');
img.src = image.src;
img.classList.add('gallery-image');
galleryImagesContainer.appendChild(img);
ctx.clearRect(0, 0, canvas.width, canvas.height);
let xPos = 0;
let yPos = 0;
for(let i=0; i<galleryArray.length; i++) {
const image = galleryArray[i];
const aspectRatio = image.width / image.height;
let canvasWidth = canvas.width / 2;
let canvasHeight = canvas.width / (2 * aspectRatio);
if (canvasHeight > canvas.height) {
canvasHeight = canvas.height / 2;
canvasWidth = canvas.height / (2 * aspectRatio);
}
ctx.drawImage(image, xPos, yPos, canvasWidth, canvasHeight);
xPos += canvasWidth;
if(xPos >= canvas.width) {
yPos += canvasHeight;
xPos = 0;
}
}
});
}
function openGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'block';
drawGalleryImages(galleryCanvas);
}
function closeGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
window.addEventListener('resize', handleResize);
</script>
</body>
</html> | 09cf58463747bdcee4aea72bd132bd65 | {
"intermediate": 0.30727675557136536,
"beginner": 0.48973992466926575,
"expert": 0.2029832899570465
} |
19,391 | something wrong here. the images got recieved from backend are not properly aligned. the "<canvas id='imageCanvas' class='image-canvas'></canvas>" is for the main current output, while gallery should contain only previous images properly and endlessly aligned and auto-fitted strictly only withing gallery container, not the main canvas output. now everything is mixed there. don't know what to do. only show what need to modify or add.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.modal-content {
display: flex;
flex-wrap: wrap;
}
.gallery-canvas-container {
position: relative;
width: 100%;
display:inline-grid;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
flex-grow: 1;
margin-right: 10px;
}
#galleryCanvas {
width: 100%;
height: 100%;
}
.gallery-image {
margin: 5px;
max-height: 100px;
max-width: 100px;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<button onclick='openGallery()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Open Gallery</button>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<div id='galleryModal' class='modal'>
<span class='close' onclick='closeGallery()'>×</span>
<div class='modal-content'>
<div class='gallery-canvas-container'>
<canvas id='galleryCanvas' class='image-canvas'></canvas>
</div>
<div class='gallery-images-container'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const galleryArray = [];
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
let generateInterval;
let isResizing = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(() => {
generateImage();
}, timeout);
generateInterval = setInterval(() => {
generateImage();
}, interval);
}
}
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(() => {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
drawGalleryImages(imageCanvas);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawGalleryImages(canvas);
isResizing = false;
});
}
function drawGalleryImages(canvas) {
const ctx = canvas.getContext('2d');
const galleryImagesContainer = document.querySelector('.gallery-images-container');
galleryImagesContainer.innerHTML = ''; // Clear previous images
galleryArray.forEach((image) => {
const img = document.createElement('img');
img.src = image.src;
img.classList.add('gallery-image');
galleryImagesContainer.appendChild(img);
ctx.clearRect(0, 0, canvas.width, canvas.height);
let xPos = 0;
let yPos = 0;
for(let i=0; i<galleryArray.length; i++) {
const image = galleryArray[i];
const aspectRatio = image.width / image.height;
let canvasWidth = canvas.width / 2;
let canvasHeight = canvas.width / (2 * aspectRatio);
if (canvasHeight > canvas.height) {
canvasHeight = canvas.height / 2;
canvasWidth = canvas.height / (2 * aspectRatio);
}
ctx.drawImage(image, xPos, yPos, canvasWidth, canvasHeight);
xPos += canvasWidth;
if(xPos >= canvas.width) {
yPos += canvasHeight;
xPos = 0;
}
}
});
}
function openGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'block';
drawGalleryImages(galleryCanvas);
}
function closeGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
window.addEventListener('resize', handleResize);
</script>
</body>
</html> | bcacc5afd1adf31822f95f94f76f8faa | {
"intermediate": 0.30727675557136536,
"beginner": 0.48973992466926575,
"expert": 0.2029832899570465
} |
19,392 | something wrong here. the images got recieved from backend are not properly aligned. the "<canvas id='imageCanvas' class='image-canvas'></canvas>" is for the main current output, while gallery should contain only previous images properly and endlessly aligned and auto-fitted strictly only withing gallery container, not the main canvas output. now everything is mixed there. don't know what to do. only show what need to modify or add.: <html>
<head>
<title>Text2Image AI</title>
<style>
html, body {
margin: 0;
padding: 0;
background-color:midnightblue;
color:white;
}
.title{
background: radial-gradient(circle at top center, #929, #519);
color: brightblue;
border-radius: 2px;
padding: 2px;
font-size: var(–font-size, 22px);
font-family: var(–font-family, monospace);
font-weight: var(–font-weight, bold);
-webkit-text-stroke: 1px darkmagenta;
text-stroke: 1px darkmagenta;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: top;
min-height: 0;
}
.control-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
}
.input-field-container {
position: absolute;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.input-field {
display:flex;
width: 100%;
height: 32px;
box-sizing: border-box;
background-color:#010130;
color:#aa50ff;
border:1px solid darkmagenta;
border-radius:6px;
padding:5px;
align-items: center;
justify-content: center;
font-size: var(--font-size, 16px);
font-family: var(--font-family, monospace);
font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
}
.gen-button-container {
position: relative;
}
.gen-button {
margin: 0;
background: radial-gradient(circle at top center, #929, #519);
color: white;
border-radius: 6px;
padding: 2px;
font-size: var(--font-size, 16px);
--font-family: var(--font-family, monospace);
--font-weight: var(--font-weight, bold);
-webkit-text-stroke: 1px rgba(139, 0, 139, 0.5);
text-stroke: 1px rgba(139, 0, 139, 1);
text-shadow: 0px 0px 0.1px rgba(255, 255, 255, 1);
}
.image-canvas {
display: flex;
align-items: center;
position: relative;
width: 100%;
background: linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to right, darkmagenta 1px, transparent 1px) 0 100%,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 0 0,
linear-gradient(to top, darkmagenta 1px, transparent 1px) 100% 0;
background-size: 25% 100%, 25% 200px, 100% 25%, 100% 25%;
background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
background-position: top left, bottom left, top left, top right;
background-color: #010130;
border-style: double dashed;
border-width: 2px;
border-color: darkmagenta;
z-index: 1;
}
.image-canvas:before {
content: '';
position: relative;
top: 2px;
left: 2px;
width: calc(100% - 4px);
height: calc(100% - 4px);
background-color: #010130;
z-index: -1;
}
.canvas-container {
position: relative;
width: 100%;
max-width: 100vh;
height: calc(5px / 0vh);
max-height: calc(5px / 0vh);
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
}
.modal-content {
display: flex;
flex-wrap: wrap;
}
.gallery-canvas-container {
position: relative;
width: 100%;
display:inline-grid;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
z-index: 2;
flex-grow: 1;
margin-right: 10px;
}
#galleryCanvas {
width: 100%;
height: 100%;
}
.gallery-image {
margin: 5px;
max-height: 100px;
max-width: 100px;
}
.progress-bar {
position: relative;
width: calc(100% - 100px);
height: 2px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
background-color: black;
}
.progress-bar-filled {
width: 0%;
height: 10px;
background-color: green;
}
.independent-container {
width: 100%;
position:relative;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
align-items: center;
margin-top: 60px;
background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;
}
</style>
</head>
<body>
<div class='container'>
<div class='control-container'>
<div class='input-field-container'>
<h1 class='title' style='margin-left: 10px;margin-right: 10px;margin-top: 10px;'>T2I AI UI</h1>
<input id='inputText' type='text' value='armoured girl riding an armored cock' class='input-field' style='flex: 1;margin-top: -6px;'>
<div class='gen-button-container'>
<button onclick='generateImage()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Gen Img</button>
</div>
</div>
</div>
<div class='independent-container'>
<label for='autoQueueCheckbox' style='margin-left: 10px;margin-right: 5px;'>Auto Queue:</label>
<input type='checkbox' id='autoQueueCheckbox' onchange='autoQueueChanged()'>
<label for='numAttemptsInput' style='margin-left: 10px;margin-right: 5px;'>Retry Attempts:</label>
<input type='number' id='numAttemptsInput' value='50' min='2' max='1000' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='intervalInput' style='margin-left: 10px;margin-right: 5px;'>Interval (sec):</label>
<input type='number' id='intervalInput' value='25' min='1' max='300' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<label for='timeoutInput' style='margin-left: 10px;margin-right: 5px;'>Timeout (sec):</label>
<input type='number' id='timeoutInput' value='120' min='12' max='600' style='width: 64px;height: 16px; background-color:#010130;
color:#aabbee;
border:1px solid darkmagenta;
border-radius:6px;'>
<button onclick='openGallery()' class='gen-button' style='border-style:none;height: 32px;margin-left: 10px;margin-right: 10px;margin-top: -6px;'>Open Gallery</button>
</div>
<div class='canvas-container'>
<canvas id='imageCanvas' class='image-canvas'></canvas>
<div class='progress-bar'>
<div class='progress-bar-filled'></div>
</div>
</div>
<div id='galleryModal' class='modal'>
<span class='close' onclick='closeGallery()'>×</span>
<div class='modal-content'>
<div class='gallery-canvas-container'>
<canvas id='galleryCanvas' class='image-canvas'></canvas>
</div>
<div class='gallery-images-container'></div>
</div>
</div>
<script>
const modelUrl = 'https://api-inference.huggingface.co/models/hogiahien/counterfeit-v30-edited';
const modelToken = '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';
const progressBarFilled = document.querySelector('.progress-bar-filled');
const imageCanvas = document.getElementById('imageCanvas');
const galleryArray = [];
const ctx = imageCanvas.getContext('2d');
let estimatedTime = 0;
let isGenerating = false;
let generateInterval;
let isResizing = false;
async function query(data) {
const response = await fetch(modelUrl, {
headers: {
Authorization: "Bearer " + modelToken
},
method: 'POST',
body: JSON.stringify(data)
});
const headers = response.headers;
const estimatedTimeString = headers.get('estimated_time');
estimatedTime = parseFloat(estimatedTimeString) * 1000;
const result = await response.blob();
return result;
}
function autoQueueChanged() {
clearInterval(generateInterval);
const autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
if (autoQueueActive) {
const timeout = parseInt(document.getElementById('timeoutInput').value) * 1000;
const interval = parseInt(document.getElementById('intervalInput').value) * 1000;
setTimeout(() => {
generateImage();
}, timeout);
generateInterval = setInterval(() => {
generateImage();
}, interval);
}
}
async function generateImage() {
if (isGenerating) {
return;
}
isGenerating = true;
const inputText = document.getElementById('inputText').value;
const numAttempts = parseInt(document.getElementById('numAttemptsInput').value);
progressBarFilled.style.width = '0%';
progressBarFilled.style.backgroundColor = 'green';
await new Promise(resolve => setTimeout(resolve, 1000));
let retryAttempts = 0;
const maxRetryAttempts = numAttempts;
let autoQueueActive = false;
while (retryAttempts < maxRetryAttempts) {
try {
const startTime = Date.now();
const timeLeft = Math.floor(estimatedTime / 1000);
const interval = setInterval(() => {
if (isGenerating) {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const progress = Math.floor((elapsedTime / timeLeft) * 1000);
progressBarFilled.style.width = progress + '%';
}
}, 1000);
const cacheBuster = new Date().getTime();
const response = await query({ inputs: inputText, cacheBuster });
const url = URL.createObjectURL(response);
let img = new Image();
img.onload = function() {
galleryArray.push(img);
drawGalleryImages(imageCanvas);
};
img.src = url;
clearInterval(interval);
progressBarFilled.style.width = '100%';
progressBarFilled.style.backgroundColor = 'darkmagenta';
break;
} catch (error) {
console.error(error);
retryAttempts++;
}
if (autoQueueActive) {
const timeout = estimatedTime + 2000;
await new Promise(resolve => setTimeout(resolve, timeout));
}
autoQueueActive = document.getElementById('autoQueueCheckbox').checked;
}
progressBarFilled.style.width = '100%';
progressBarFilled.style.height = '2px';
progressBarFilled.style.backgroundColor = 'green';
isGenerating = false;
}
function handleResize() {
if (isResizing) return;
isResizing = true;
requestAnimationFrame(() => {
handleResize();
generateImage();
const container = document.querySelector('.canvas-container');
const canvas = document.getElementById('imageCanvas');
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const aspectRatio = canvas.width / canvas.height;
let canvasWidth = containerWidth;
let canvasHeight = containerWidth / aspectRatio;
if (canvasHeight > containerHeight) {
canvasHeight = containerHeight;
canvasWidth = canvasHeight * aspectRatio;
}
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawGalleryImages(canvas);
isResizing = false;
});
}
function drawGalleryImages(canvas) {
const ctx = canvas.getContext('2d');
const galleryImagesContainer = document.querySelector('.gallery-images-container');
galleryImagesContainer.innerHTML = ''; // Clear previous images
galleryArray.forEach((image) => {
const img = document.createElement('img');
img.src = image.src;
img.classList.add('gallery-image');
galleryImagesContainer.appendChild(img);
ctx.clearRect(0, 0, canvas.width, canvas.height);
let xPos = 0;
let yPos = 0;
for(let i=0; i<galleryArray.length; i++) {
const image = galleryArray[i];
const aspectRatio = image.width / image.height;
let canvasWidth = canvas.width / 2;
let canvasHeight = canvas.width / (2 * aspectRatio);
if (canvasHeight > canvas.height) {
canvasHeight = canvas.height / 2;
canvasWidth = canvas.height / (2 * aspectRatio);
}
ctx.drawImage(image, xPos, yPos, canvasWidth, canvasHeight);
xPos += canvasWidth;
if(xPos >= canvas.width) {
yPos += canvasHeight;
xPos = 0;
}
}
});
}
function openGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'block';
drawGalleryImages(galleryCanvas);
}
function closeGallery() {
const galleryModal = document.getElementById('galleryModal');
galleryModal.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', function() {
handleResize();
generateImage();
});
window.addEventListener('resize', handleResize);
</script>
</body>
</html> | adc8c76d9f7e64fa53bc8f808ccd5441 | {
"intermediate": 0.30727675557136536,
"beginner": 0.48973992466926575,
"expert": 0.2029832899570465
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.