File size: 1,480 Bytes
8a06a42
 
 
51af9e1
529a4fd
8a06a42
 
 
 
529a4fd
8a06a42
 
 
 
 
 
 
 
 
 
 
639176c
e6e311a
639176c
 
 
 
 
 
 
 
 
8a06a42
 
 
 
 
 
 
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
import gradio as gr
from diffusers import StableDiffusionPipeline

model_id = "cagliostrolab/animagine-xl-3.1"
pipe = StableDiffusionPipeline.from_pretrained(model_id)

def generate_image(prompt, negative_prompt, seed, cfg_scale, strength, steps):
  if seed == -1:
    seed = None
  generator = torch.manual_seed(seed)
  image = pipe(
      prompt,
      negative_prompt=negative_prompt,
      guidance_scale=cfg_scale,
      num_inference_steps=int(steps),
      strength=strength,
      generator=generator,
  ).images[0]
  return image

with gr.Blocks() as demo:
  with gr.Tabs():
    with gr.Tab("Основные настройки"):
      with gr.Row():
        prompt = gr.Textbox(label="Подсказка")
    with gr.Tab("Расширенные настройки"):
      with gr.Row():
        negative_prompt = gr.Textbox(label="Негативная подсказка")
        seed = gr.Slider(label="Seed", minimum=-1, maximum=2147483647, step=1, value=-1)
        cfg_scale = gr.Slider(label="CFG", minimum=1.0, maximum=15.0, step=0.5, value=7.5)
        strength = gr.Slider(label="Strength", minimum=0.0, maximum=1.0, step=0.01, value=0.7)
        steps = gr.Slider(label="Sampling steps", minimum=1, maximum=100, step=1, value=50)

  btn = gr.Button("Сгенерировать")
  output = gr.Image(label="Результат")

  btn.click(fn=generate_image, inputs=[prompt, negative_prompt, seed, cfg_scale, strength, steps], outputs=output)

demo.launch()