profaker commited on
Commit
6975d0e
·
verified ·
1 Parent(s): 74849c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -15
app.py CHANGED
@@ -2,13 +2,13 @@ import gradio as gr
2
  import torch
3
  import numpy as np
4
  from PIL import Image
5
-
6
  from diffusers import AutoPipelineForInpainting, UNet2DConditionModel
7
  import diffusers
8
  from share_btn import community_icon_html, loading_icon_html, share_js
9
 
10
-
11
- pipe = AutoPipelineForInpainting.from_pretrained("SG161222/Realistic_Vision_V5.0_noVAE")
12
 
13
  def read_content(file_path: str) -> str:
14
  """read the content of target file
@@ -18,7 +18,7 @@ def read_content(file_path: str) -> str:
18
 
19
  return content
20
 
21
- def predict(dict, prompt="", negative_prompt="", guidance_scale=7.5, steps=30, strength=1.0, scheduler="DPMSolverMultistepScheduler-Karras"):
22
  if negative_prompt == "":
23
  negative_prompt = None
24
  scheduler_class_name = scheduler.split("-")[0]
@@ -30,7 +30,7 @@ def predict(dict, prompt="", negative_prompt="", guidance_scale=7.5, steps=30, s
30
  add_kwargs["algorithm_type"] = "sde-dpmsolver++"
31
 
32
  scheduler = getattr(diffusers, scheduler_class_name)
33
- pipe.scheduler = scheduler.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", subfolder="scheduler", **add_kwargs)
34
 
35
  init_image = dict["image"]
36
  mask = dict["mask"]
@@ -91,7 +91,7 @@ with image_blocks as demo:
91
  with gr.Row(equal_height=True):
92
  guidance_scale = gr.Number(value=7.5, minimum=1.0, maximum=20.0, step=0.1, label="guidance_scale")
93
  steps = gr.Number(value=20, minimum=10, maximum=100, step=1, label="steps")
94
- strength = gr.Number(value=0.99, minimum=0.01, maximum=1.0, step=0.01, label="strength")
95
  negative_prompt = gr.Textbox(label="negative_prompt", placeholder="Your negative prompt", info="what you don't want to see in the image")
96
  with gr.Row(equal_height=True):
97
  schedulers = ["DEISMultistepScheduler", "HeunDiscreteScheduler", "EulerDiscreteScheduler", "DPMSolverMultistepScheduler", "DPMSolverMultistepScheduler-Karras", "DPMSolverMultistepScheduler-Karras-SDE"]
@@ -102,20 +102,12 @@ with image_blocks as demo:
102
  with gr.Group(elem_id="share-btn-container", visible=False) as share_btn_container:
103
  community_icon = gr.HTML(community_icon_html)
104
  loading_icon = gr.HTML(loading_icon_html)
105
- share_button = gr.Button("Share to community", elem_id="share-btn",visible=True)
106
 
107
 
108
  btn.click(fn=predict, inputs=[image, prompt, negative_prompt, guidance_scale, steps, strength, scheduler], outputs=[image_out, share_btn_container], api_name='run')
109
  prompt.submit(fn=predict, inputs=[image, prompt, negative_prompt, guidance_scale, steps, strength, scheduler], outputs=[image_out, share_btn_container])
110
  share_button.click(None, [], [], _js=share_js)
111
 
112
- gr.HTML(
113
- """
114
- <div class="footer">
115
- <p>Model by <a href="https://huggingface.co/diffusers" style="text-decoration: underline;" target="_blank">Diffusers</a> - Gradio Demo by 🤗 Hugging Face
116
- </p>
117
- </div>
118
- """
119
- )
120
 
121
  image_blocks.queue(max_size=25,api_open=True).launch(show_api=True)
 
2
  import torch
3
  import numpy as np
4
  from PIL import Image
5
+ from diffusers.models import AutoencoderKL
6
  from diffusers import AutoPipelineForInpainting, UNet2DConditionModel
7
  import diffusers
8
  from share_btn import community_icon_html, loading_icon_html, share_js
9
 
10
+ vae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-mse")
11
+ pipe = AutoPipelineForInpainting.from_pretrained("SG161222/Realistic_Vision_V5.0_noVAE",vae=vae)
12
 
13
  def read_content(file_path: str) -> str:
14
  """read the content of target file
 
18
 
19
  return content
20
 
21
+ def predict(dict, prompt="", negative_prompt="", guidance_scale=7.5, steps=30, strength=0.8, scheduler="DPMSolverMultistepScheduler-Karras"):
22
  if negative_prompt == "":
23
  negative_prompt = None
24
  scheduler_class_name = scheduler.split("-")[0]
 
30
  add_kwargs["algorithm_type"] = "sde-dpmsolver++"
31
 
32
  scheduler = getattr(diffusers, scheduler_class_name)
33
+ pipe.scheduler = scheduler.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", subfolder="scheduler", **add_kwargs)
34
 
35
  init_image = dict["image"]
36
  mask = dict["mask"]
 
91
  with gr.Row(equal_height=True):
92
  guidance_scale = gr.Number(value=7.5, minimum=1.0, maximum=20.0, step=0.1, label="guidance_scale")
93
  steps = gr.Number(value=20, minimum=10, maximum=100, step=1, label="steps")
94
+ strength = gr.Number(value=0.8, minimum=0.01, maximum=1.0, step=0.01, label="strength")
95
  negative_prompt = gr.Textbox(label="negative_prompt", placeholder="Your negative prompt", info="what you don't want to see in the image")
96
  with gr.Row(equal_height=True):
97
  schedulers = ["DEISMultistepScheduler", "HeunDiscreteScheduler", "EulerDiscreteScheduler", "DPMSolverMultistepScheduler", "DPMSolverMultistepScheduler-Karras", "DPMSolverMultistepScheduler-Karras-SDE"]
 
102
  with gr.Group(elem_id="share-btn-container", visible=False) as share_btn_container:
103
  community_icon = gr.HTML(community_icon_html)
104
  loading_icon = gr.HTML(loading_icon_html)
105
+ share_button = gr.Button("Share to community", elem_id="share-btn",visible=False)
106
 
107
 
108
  btn.click(fn=predict, inputs=[image, prompt, negative_prompt, guidance_scale, steps, strength, scheduler], outputs=[image_out, share_btn_container], api_name='run')
109
  prompt.submit(fn=predict, inputs=[image, prompt, negative_prompt, guidance_scale, steps, strength, scheduler], outputs=[image_out, share_btn_container])
110
  share_button.click(None, [], [], _js=share_js)
111
 
 
 
 
 
 
 
 
 
112
 
113
  image_blocks.queue(max_size=25,api_open=True).launch(show_api=True)