File size: 2,549 Bytes
ff1df2a
 
 
7d9be07
056a538
f6b6ceb
7fcead6
f6b6ceb
 
7d9be07
 
056a538
f6b6ceb
 
 
aeb71ff
f4fec5a
aeb71ff
056a538
 
7d9be07
 
f6b6ceb
7fcead6
f6b6ceb
a5b71c1
0619f29
7d9be07
5cbcb31
 
 
 
 
 
 
 
 
 
 
 
0619f29
75d0567
0619f29
5cbcb31
 
 
 
 
 
 
 
0619f29
70ba535
7d9be07
 
5cbcb31
 
 
 
 
 
 
 
 
 
 
a5b71c1
0619f29
7d9be07
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import gradio as gr
import requests

# Базовые настройки
prompt = gr.Textbox(label="Prompt")
models = gr.Radio(
    ["Bard", "DALL-E 2", "VQGAN+CLIP", "VQGAN", "CLIP", "InceptionV3", "VQGAN+CLIP-ViT-B16", "VQGAN+CLIP-ViT-B32", "VQGAN+CLIP-ViT-L", "VQGAN+CLIP-ViT-H", "VQGAN+CLIP-ViT-XL"],
    label="Model",
)

# Расширенные настройки
negative_prompt = gr.Textbox(label="Negative Prompt")
sampling_method = gr.Radio(
    ["random", "greedy", "nucleus", "top_k", "top_p"], label="Sampling Method"
)
sampling_steps = gr.Number(
    label="Sampling Steps", value=100, min_val=1, max_val=1000
)
cfg_scale = gr.Number(label="CFG Scale", min=0.1, max=10.0, default=1.0)
seed = gr.Number(label="Seed", min=0, max=2**31, default=0)

# Улучшение качества
algorithm = gr.Radio(
    ["nearest", "bilinear", "bicubic", "lanczos", "cubic", "mitchell", "bicubic_nn", "bicubic_nn_diff", "bicubic_nn_diff_v2"], label="Algorithm"
)

# Функция генерации изображения
def generate_image(prompt, model, negative_prompt, sampling_method, sampling_steps, cfg_scale, seed):
    url = "https://api.huggingface.co/models/text-to-image/v1/generate"
    data = {
        "prompt": prompt,
        "model": model,
        "negative_prompt": negative_prompt,
        "sampling_method": sampling_method,
        "sampling_steps": sampling_steps,
        "cfg_scale": cfg_scale,
        "seed": seed,
    }
    response = requests.post(url, json=data)
    image = response.json()["image"]
    return image

# Функция улучшения качества изображения
def improve_quality(image, algorithm):
    url = "https://api.huggingface.co/models/text-to-image/v1/improve-quality"
    data = {
        "image": image,
        "algorithm": algorithm,
    }
    response = requests.post(url, json=data)
    image = response.json()["image"]
    return image

# Основная функция
def main():
    gr.Interface(
        generate_image,
        inputs=[prompt, models, negative_prompt, sampling_method, sampling_steps, cfg_scale, seed],
        outputs=gr.outputs.Image(),
        title="Gradio Image Generator",
        tabs=[
            gr.Tab("Базовые настройки", [prompt, models]),
            gr.Tab("Расширенные настройки", [negative_prompt, sampling_method, sampling_steps, cfg_scale, seed]),
            gr.Tab("Улучшение качества", [algorithm]),
        ],
    ).launch()

if __name__ == "__main__":
    main()