File size: 1,122 Bytes
19847b6
04ef268
 
 
 
6a2f9ae
04ef268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import spaces
import gradio as gr
from src.util.base import *
from src.util.params import *

@spaces.GPU()
def display_guidance_images(
    prompt, seed, num_inference_steps, guidance_values, progress=gr.Progress()
):
    text_embeddings = get_text_embeddings(prompt)
    latents = generate_latents(seed)

    progress(0)
    images = []
    guidance_values = guidance_values.replace(",", " ").split()
    num_images = len(guidance_values)

    for i in range(num_images):
        progress(i / num_images)
        image = generate_images(
            latents,
            text_embeddings,
            num_inference_steps,
            guidance_scale=int(guidance_values[i]),
        )
        images.append((image, "{}".format(int(guidance_values[i]))))

    fname = "guidance"
    tab_config = {
        "Tab": "Guidance",
        "Prompt": prompt,
        "Guidance Scale Values": guidance_values,
        "Number of Inference Steps per Image": num_inference_steps,
        "Seed": seed,
    }
    export_as_zip(images, fname, tab_config)
    return images, f"outputs/{fname}.zip"


__all__ = ["display_guidance_images"]