File size: 1,981 Bytes
6af7294
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
async ()  => {
    const urlParams = new URLSearchParams(window.location.search);
    const username = urlParams.get('username');
    const artworkId = urlParams.get('artworkId');
    
    const LOAD_URL = `http://127.0.0.1:5000/v1/api/load-parameters/${artworkId}`;
    const response = await fetch(LOAD_URL, {
        method: 'GET',
        headers: {
            'X-Requested-With': 'XMLHttpRequest',
        }
    });

    // Check if the response is okay
    if (!response.ok) {
        console.error("An error occurred while fetching the parameters.");
        return;
    }

    const parameters = await response.json(); // Assuming you're getting a JSON response

    // Get the necessary elements
    const gradioEl = document.querySelector('gradio-app');
    const promptInput = gradioEl.querySelector('#prompt-text-input textarea');
    const negativePromptInput = gradioEl.querySelector('#negative-prompt-text-input textarea');

    // Get the slider inputs
    const guidanceScaleInput = gradioEl.querySelector('#guidance-scale-slider input');
    const numInferenceStepInput = gradioEl.querySelector('#num-inference-step-slider input');
    const imageSizeInput = gradioEl.querySelector('#image-size-slider input');
    const seedInput = gradioEl.querySelector('#seed-slider input');

    // Get the dropdown inputs
    const modelDropdown = gradioEl.querySelector('#model-dropdown input');
    const schedulerDropdown = gradioEl.querySelector('#scheduler-dropdown input');

    // Set the values based on the parameters received
    promptInput.value = parameters.text_prompt;
    negativePromptInput.value = parameters.negative_prompt;
    guidanceScaleInput.value = parameters.model_guidance_scale;
    numInferenceStepInput.value = parameters.model_num_steps;
    imageSizeInput.value = parameters.model_image_size;
    seedInput.value = parameters.seed;
    modelDropdown.value = parameters.model_name;
    schedulerDropdown.value = parameters.scheduler_name;
}