ApplyDesign commited on
Commit
aca7a56
·
verified ·
1 Parent(s): 31ad934

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -4
app.py CHANGED
@@ -1,8 +1,43 @@
1
- from diffusers import StableDiffusionPipeline, StableDiffusionUpscalePipeline
2
  import gradio as gr
 
 
 
3
 
4
- # pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
5
- pipe = StableDiffusionUpscalePipeline.from_pretrained("stabilityai/stable-diffusion-x4-upscaler")
 
 
 
6
 
 
7
 
8
- gr.Interface.from_pipeline(pipe).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import upscaler
3
+ import os
4
+ from PIL import Image
5
 
6
+ def upscale_image(prompt,negative_prompt, rows=3,seed=0, image=None,enable_custom_sliders=False,guidance=7,iterations=50,xformers_input=False,cpu_offload_input=False,attention_slicing_input=False):
7
+ cols = rows
8
+ output_image = upscaler.upscale_image(image, int(rows), int(cols),int(seed), prompt,negative_prompt,xformers_input,cpu_offload_input,attention_slicing_input,enable_custom_sliders,guidance,iterations)
9
+ output_image_path = "result.png"
10
+ output_image.save(output_image_path)
11
 
12
+ return output_image_path
13
 
14
+
15
+ image_input = gr.inputs.Image(label="Input Image")
16
+ prompt_input = gr.inputs.Textbox(default="8k, photography, cgi, unreal engine, octane render, best quality",label="Prompt")
17
+ negative_prompt_input = gr.inputs.Textbox(default="jpeg artifacts, lowres, bad quality",label="Negative prompt")
18
+ seed_input = gr.inputs.Number(default=-1, label="Seed")
19
+ row_input = gr.inputs.Number(default=1, label="Tile grid dimension amount (number of rows and columns) - v x v")
20
+ xformers_input = gr.inputs.Checkbox(default=True,label="Enable Xformers memory efficient attention")
21
+ enable_custom_sliders = gr.inputs.Checkbox(default=False,label="(NOT RECOMMENDED) Click to enable the sliders below; if unchecked, it will ignore them and use the default settings")
22
+ cpu_offload_input = gr.inputs.Checkbox(default=True,label="Enable sequential CPU offload")
23
+ attention_slicing_input = gr.inputs.Checkbox(default=True,label="Enable attention slicing")
24
+ output_image = gr.outputs.Image(label="Output Image",type='pil')
25
+ guidance = gr.Slider(2, 15, 7, step=1, label='Guidance Scale: How much the AI influences the Upscaling.')
26
+ iterations = gr.Slider(10, 75, 50, step=1, label='Number of Iterations')
27
+ #save_png_button, save_png_halfsize_button ; I don't know how to implement them
28
+ save_png_button = gr.Button(label="Save as a PNG image") # Added this button with the save_png function
29
+ save_png_halfsize_button = gr.Button(label="Save as a PNG image (half size)") # Added this button with the save_png_halfsize function
30
+
31
+ gr.Interface(fn=upscale_image,
32
+ inputs=[prompt_input,negative_prompt_input,row_input,
33
+ seed_input,
34
+ image_input,
35
+ enable_custom_sliders,
36
+ guidance,
37
+ iterations,
38
+ xformers_input,
39
+ cpu_offload_input,
40
+ attention_slicing_input],
41
+ outputs=[output_image],
42
+ title="Stable Diffusion x4 Upscaler - Web GUI",
43
+ allow_flagging=False).launch()