DmitrMakeev commited on
Commit
518ef32
·
1 Parent(s): 5888405

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -29
app.py CHANGED
@@ -2,9 +2,10 @@ import gradio as gr
2
  import torch
3
  import modin.pandas as pd
4
  from diffusers import DiffusionPipeline
 
5
  device = "cuda" if torch.cuda.is_available() else "cpu"
6
  if torch.cuda.is_available():
7
- PYTORCH_CUDA_ALLOC_CONF = {'max_split_size_mb': 6000}
8
  torch.cuda.max_memory_allocated(device=device)
9
  torch.cuda.empty_cache()
10
  pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
@@ -19,35 +20,21 @@ else:
19
  pipe = pipe.to(device)
20
  refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True)
21
  refiner = refiner.to(device)
22
- def genie(prompt, negative_prompt, height, width, scale, steps, seed, strength):
 
23
  generator = torch.Generator(device=device).manual_seed(seed)
24
  int_image = pipe(prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, num_images_per_prompt=1, generator=generator, output_type="latent").images
25
  image = refiner(prompt=prompt, negative_prompt=negative_prompt, image=int_image).images[0]
26
  return image
27
- models = [
28
- {"name": "Модель 1", "value": "models/cag/anything-v3-1"},
29
- {"name": "Модель 2", "value": "models/emilianJR/AnyLORA"}
30
- ]
31
- current_model = models[0]
32
- def set_model(selected_model):
33
- global current_model
34
- current_model = models[selected_model]
35
- input_prompt = gr.inputs.Textbox(label='Что вы хотите, чтобы ИИ генерировал')
36
- input_negative_prompt = gr.inputs.Textbox(label='Что вы не хотите, чтобы ИИ генерировал')
37
- input_height = gr.inputs.Slider(512, 1024, 768, step=128, label='Высота')
38
- input_width = gr.inputs.Slider(512, 1024, 768, step=128, label='Ширина')
39
- input_scale = gr.inputs.Slider(1, 15, 10, label='Шкала навигации')
40
- input_steps = gr.inputs.Slider(25, maximum=50, value=25, step=1, label='Количество итераций')
41
- input_seed = gr.inputs.Slider(label="Зерно", minimum=0, maximum=987654321987654321, step=1, randomize=True)
42
- input_strength = gr.inputs.Slider(label='Сила', minimum=0, maximum=1, step=0.05, default_value=0.5)
43
- model_names = [m["name"] for m in models]
44
- model_selection = gr.inputs.Dropdown(
45
- choices=model_names,
46
- type="index",
47
- label="Выберите модель",
48
- default=0,
49
- onchange=set_model
50
- )
51
- output_image = gr.outputs.Image(label="Результат")
52
- iface = gr.Interface(fn=genie, inputs=[input_prompt, input_negative_prompt, input_height, input_width, input_scale, input_steps, input_seed, input_strength, model_selection], outputs=output_image, title="Стабильная Диффузия - SDXL - txt2img", article="")
53
- iface.launch()
 
2
  import torch
3
  import modin.pandas as pd
4
  from diffusers import DiffusionPipeline
5
+
6
  device = "cuda" if torch.cuda.is_available() else "cpu"
7
  if torch.cuda.is_available():
8
+ PYTORCH_CUDA_ALLOC_CONF={'max_split_size_mb': 6000}
9
  torch.cuda.max_memory_allocated(device=device)
10
  torch.cuda.empty_cache()
11
  pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
 
20
  pipe = pipe.to(device)
21
  refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True)
22
  refiner = refiner.to(device)
23
+
24
+ def genie (prompt, negative_prompt, height, width, scale, steps, seed, strength):
25
  generator = torch.Generator(device=device).manual_seed(seed)
26
  int_image = pipe(prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, num_images_per_prompt=1, generator=generator, output_type="latent").images
27
  image = refiner(prompt=prompt, negative_prompt=negative_prompt, image=int_image).images[0]
28
  return image
29
+
30
+ gr.Interface(fn=genie, inputs=[gr.Textbox(label='Что вы хотите, чтобы ИИ генерировал'),
31
+ gr.Textbox(label='Что вы не хотите, чтобы ИИ генерировал'),
32
+ gr.Slider(512, 1024, 768, step=128, label='Высота'),
33
+ gr.Slider(512, 1024, 768, step=128, label='Ширина'),
34
+ gr.Slider(1, 15, 10, label='Шкала навигации'),
35
+ gr.Slider(25, maximum=50, value=25, step=1, label='Количество итераций'),
36
+ gr.Slider(label="Зерно", minimum=0, maximum=987654321987654321, step=1, randomize=True),
37
+ gr.Slider(label='Сила', minimum=0, maximum=1, step=.05, value=.5)],
38
+ outputs='image',
39
+ title="Стабильная Диффузия - SDXL - txt2img",
40
+ article = "<br><br><br><br><br>").launch(debug=True, max_threads=80)