Krebzonide
commited on
Commit
•
d2789ce
1
Parent(s):
cb6054c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#Downloading other people's code so we don't have to write it ourselves
|
2 |
+
from diffusers import StableDiffusionPipeline
|
3 |
+
import gradio as gr
|
4 |
+
import torch
|
5 |
+
|
6 |
+
pipe = StableDiffusionPipeline.from_pretrained( #Downloading the model and naming it "pipe"
|
7 |
+
"Lykon/dreamshaper-8", #Name of the model we will download
|
8 |
+
torch_dtype=torch.float16,) #Forces it to download the small version which saves time and computer memory
|
9 |
+
|
10 |
+
pipe.to("cuda") #Move the model to the GPU because it's faster than the CPU
|
11 |
+
|
12 |
+
def generate( #Creates a function called "generate" that takes creates the image using the pipeline
|
13 |
+
prompt, negative_prompt, sampling_steps, guidance_scale, #These are the parameters that control image generation
|
14 |
+
progress=gr.Progress(track_tqdm=True)): #Shows you a progress bar as your image is generated
|
15 |
+
image = pipe( #The function that uses the pipeline to generate images
|
16 |
+
prompt, negative_prompt=neg_prompt, num_inference_steps=sampling_steps, guidance_scale=guidance_scale #The parameters that the pipeline will use
|
17 |
+
).image #Separates the image from the other data returned
|
18 |
+
return image #Sends the image back to whoever called this function
|
19 |
+
|
20 |
+
with gr.Blocks() as demo: #Creates a page on a website that you can look at and click on
|
21 |
+
with gr.Column(): #Creates a column
|
22 |
+
prompt = gr.Textbox(label="Prompt") #A text box so you can type in the prompt
|
23 |
+
negative_prompt = gr.Textbox(label="Negative Prompt") #A text box so you can type in the negative prompt
|
24 |
+
with gr.Row(): #Creates a row
|
25 |
+
submit_btn = gr.Button("Generate") #A button for you to click to generate images
|
26 |
+
samp_steps = gr.Slider(1, 50, value=25, step=1, label="Sampling steps") #A slider to input the sampling steps you want
|
27 |
+
guide_scale = gr.Slider(1, 10, value=6, step=0.5, label="Guidance scale") #A slider to input the guidance scale you want
|
28 |
+
image = gr.Image(label="Generated images") #A gallery displays images
|
29 |
+
|
30 |
+
submit_btn.click( #When you click the button this will run
|
31 |
+
generate, #Runs the generate function
|
32 |
+
[prompt, negative_prompt, samp_steps, guide_scale], #Passes the value of these objects as inputs to the function
|
33 |
+
[image], #Gives the output of the function to this object
|
34 |
+
queue=True) #Allows users to wait in a queue until the GPU isn't busy
|
35 |
+
|
36 |
+
demo.launch(debug=True) #Tells the program to run the page so that you can look at it and click on it
|