Rooni commited on
Commit
dabd818
·
verified ·
1 Parent(s): 45f261e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import StableDiffusionPipeline
3
+ import torch
4
+
5
+ model_id = "runwayml/stable-diffusion-v1-5"
6
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
7
+ pipe = pipe.to("cuda")
8
+
9
+ def generate_image(prompt, guidance_scale=7.5, num_inference_steps=50):
10
+ image = pipe(prompt, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps).images[0]
11
+ return image
12
+
13
+ with gr.Blocks() as demo:
14
+ with gr.Tab("Генерация"):
15
+ with gr.Row():
16
+ with gr.Column():
17
+ prompt_input = gr.Textbox(label="Введите описание картинки", lines=2)
18
+ generate_button = gr.Button(label="Сгенерировать")
19
+ with gr.Column():
20
+ image_output = gr.Image(label="Результат")
21
+ with gr.Tab("Настройки"):
22
+ with gr.Row():
23
+ guidance_scale_slider = gr.Slider(label="Guidance Scale (чем больше, тем больше соответствует описанию)", minimum=1, maximum=20, step=0.5, value=7.5)
24
+ num_inference_steps_slider = gr.Slider(label="Number of Inference Steps (чем больше, тем качественнее, но дольше)", minimum=10, maximum=100, step=10, value=50)
25
+
26
+ generate_button.click(fn=generate_image,
27
+ inputs=[prompt_input, guidance_scale_slider, num_inference_steps_slider],
28
+ outputs=image_output)
29
+
30
+ demo.launch()