Silence1412 commited on
Commit
b5a6313
1 Parent(s): 469cc9a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import torch
4
+ from PIL import Image
5
+ from diffusers import StableDiffusionPipeline
6
+
7
+ model_id = "runwayml/stable-diffusion-v1-5"
8
+
9
+ pipe = StableDiffusionPipeline.from_pretrained(model_id).to('cpu')
10
+
11
+ def infer(prompt, negative, steps, scale, seed):
12
+ generator = torch.Generator(device='cpu').manual_seed(seed)
13
+ img = pipe(
14
+ prompt,
15
+ height=512,
16
+ width=512,
17
+ num_inference_steps=steps,
18
+ guidance_scale=scale,
19
+ negative_prompt = negative,
20
+ generator=generator,
21
+ ).images
22
+ return img
23
+
24
+ block = gr.Blocks()
25
+
26
+ with block:
27
+ with gr.Group():
28
+ with gr.Box():
29
+ with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
30
+ with gr.Column():
31
+ text = gr.Textbox(
32
+ label="Enter your prompt",
33
+ show_label=False,
34
+ max_lines=1,
35
+ placeholder="Enter your prompt",
36
+ ).style(
37
+ border=(True, False, True, True),
38
+ rounded=(True, False, False, True),
39
+ container=False,
40
+ )
41
+
42
+ negative = gr.Textbox(
43
+ label="Enter your negative prompt",
44
+ show_label=False,
45
+ placeholder="Enter a negative prompt",
46
+ elem_id="negative-prompt-text-input",
47
+ ).style(
48
+ border=(True, False, True, True),
49
+ rounded=(True, False, False, True),container=False,
50
+ )
51
+
52
+ btn = gr.Button("Generate image").style(
53
+ margin=False,
54
+ rounded=(False, True, True, False),
55
+ )
56
+ gallery = gr.Gallery(
57
+ label="Generated images", show_label=False, elem_id="gallery"
58
+ ).style(columns=(1, 2), height="auto")
59
+
60
+ with gr.Row(elem_id="advanced-options"):
61
+ samples = gr.Slider(label="Images", minimum=1, maximum=1, value=1, step=1, interactive=False)
62
+ steps = gr.Slider(label="Steps", minimum=1, maximum=50, value=12, step=1, interactive=True)
63
+ scale = gr.Slider(label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1, interactive=True)
64
+ seed = gr.Slider(label="Random seed",minimum=0,maximum=2147483647,step=1,randomize=True,interactive=True)
65
+
66
+ btn.click(infer, inputs=[text, negative, steps, scale, seed], outputs=[gallery])
67
+
68
+ block.launch(show_api=False)