File size: 1,408 Bytes
7b31aca
 
 
 
857a4f1
7b31aca
 
 
 
 
857a4f1
 
7b31aca
 
 
 
 
 
 
 
 
857a4f1
 
7a474e6
857a4f1
 
 
 
7b31aca
 
 
857a4f1
 
 
 
 
7b31aca
 
 
 
 
 
 
 
 
 
 
 
857a4f1
7b31aca
 
 
 
 
857a4f1
 
 
 
7b31aca
 
857a4f1
7b31aca
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import gradio as gr
import numpy as np
import random

import spaces  # [uncomment to use ZeroGPU]
from diffusers import DiffusionPipeline
import torch


model_ids = [
    "Prgckwb/trpfrog-sd3.5-large",
    "Prgckwb/trpfrog-diffusion",
]

if torch.cuda.is_available():
    torch_dtype = torch.float16
    device = "cuda"
else:
    torch_dtype = torch.float32
    device = "cpu"

pipelines = {
    model_id: DiffusionPipeline.from_pretrained(
        model_id, torch_dtype=torch_dtype
    )
    for model_id in model_ids
}


@spaces.GPU()
def inference(
    model_id: str,
    prompt: str,
    width: int,
    height: int,
    progress=gr.Progress(track_tqdm=True),
):
    pipe = pipelines[model_id].to(device)

    image = pipe(
        prompt=prompt,
        width=width,
        height=height,
    ).images[0]

    return image


if __name__ == "__main__":
    theme = gr.themes.Ocean()

    demo = gr.Interface(
        fn=inference,
        inputs=[
            gr.Dropdown(label="Model", choices=model_ids, value=model_ids[0]),
            gr.Textbox(label="Prompt", placeholder="an icon of trpfrog"),
            gr.Slider(label="Width", minimum=64, maximum=1024, step=64, value=1024),
            gr.Slider(label="Height", minimum=64, maximum=1024, step=64, value=1024),
        ],
        outputs=[
            gr.Image(label="Output"),
        ],
        theme=theme,
    )
    demo.queue().launch()