KingNish commited on
Commit
20b703a
·
verified ·
1 Parent(s): 3a818dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -25
app.py CHANGED
@@ -10,7 +10,6 @@ from diffusers import DiffusionPipeline, StableDiffusionXLPipeline, EDMEulerSche
10
  from custom_pipeline import CosStableDiffusionXLInstructPix2PixPipeline
11
  from huggingface_hub import hf_hub_download
12
  from huggingface_hub import InferenceClient
13
- from diffusers import StableDiffusion3Pipeline, SD3Transformer2DModel, FlowMatchEulerDiscreteScheduler
14
 
15
  device = "cuda" if torch.cuda.is_available() else "cpu"
16
  dtype = torch.float16
@@ -32,30 +31,11 @@ To optimize image results:
32
  - Experiment with different **random seeds** and **CFG values** for varied outcomes.
33
  - **Rephrase your instructions** for potentially better results.
34
  - **Increase the number of steps** for enhanced edits.
35
- """
36
-
37
- def set_timesteps_patched(self, num_inference_steps: int, device = None):
38
- self.num_inference_steps = num_inference_steps
39
-
40
- ramp = np.linspace(0, 1, self.num_inference_steps)
41
- sigmas = torch.linspace(math.log(self.config.sigma_min), math.log(self.config.sigma_max), len(ramp)).exp().flip(0)
42
-
43
- sigmas = (sigmas).to(dtype=torch.float32, device=device)
44
- self.timesteps = self.precondition_noise(sigmas)
45
-
46
- self.sigmas = torch.cat([sigmas, torch.zeros(1, device=sigmas.device)])
47
- self._step_index = None
48
- self._begin_index = None
49
- self.sigmas = self.sigmas.to("cpu")
50
 
51
  # Image Editor
52
- edit_file = hf_hub_download(repo_id="stabilityai/cosxl", filename="cosxl_edit.safetensors")
53
- EDMEulerScheduler.set_timesteps = set_timesteps_patched
54
- pipe_edit = StableDiffusionXLInstructPix2PixPipeline.from_single_file(
55
- edit_file, num_in_channels=8, is_cosxl_edit=True, vae=vae, torch_dtype=torch.float16,
56
- )
57
- pipe_edit.scheduler = EDMEulerScheduler(sigma_min=0.002, sigma_max=120.0, sigma_data=1.0, prediction_type="v_prediction")
58
- pipe_edit.to("cuda")
59
 
60
  # Generator
61
  @spaces.GPU(duration=30, queue=False)
@@ -66,7 +46,7 @@ def king(type ,
66
  randomize_seed: bool = False,
67
  seed: int = 25,
68
  text_cfg_scale: float = 7.3,
69
- image_cfg_scale: float = 1.7,
70
  width: int = 1024,
71
  height: int = 1024,
72
  guidance_scale: float = 6,
@@ -193,7 +173,7 @@ with gr.Blocks(css=css) as demo:
193
 
194
  with gr.Row():
195
  text_cfg_scale = gr.Number(value=7.3, step=0.1, label="Text CFG", interactive=True)
196
- image_cfg_scale = gr.Number(value=1.7, step=0.1,label="Image CFG", interactive=True)
197
  guidance_scale = gr.Number(value=6.0, step=0.1, label="Image Generation Guidance Scale", interactive=True)
198
  steps = gr.Number(value=25, step=1, label="Steps", interactive=True)
199
  randomize_seed = gr.Radio(
 
10
  from custom_pipeline import CosStableDiffusionXLInstructPix2PixPipeline
11
  from huggingface_hub import hf_hub_download
12
  from huggingface_hub import InferenceClient
 
13
 
14
  device = "cuda" if torch.cuda.is_available() else "cpu"
15
  dtype = torch.float16
 
31
  - Experiment with different **random seeds** and **CFG values** for varied outcomes.
32
  - **Rephrase your instructions** for potentially better results.
33
  - **Increase the number of steps** for enhanced edits.
34
+ """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  # Image Editor
37
+ pipe_edit = StableDiffusionInstructPix2PixPipeline.from_pretrained( "vinesmsuic/magicbrush-jul7", torch_dtype=torch.float16, vae=vae ).to("cuda")
38
+ pipe_edit.scheduler = EulerAncestralDiscreteScheduler(pipe_edit.scheduler.config)
 
 
 
 
 
39
 
40
  # Generator
41
  @spaces.GPU(duration=30, queue=False)
 
46
  randomize_seed: bool = False,
47
  seed: int = 25,
48
  text_cfg_scale: float = 7.3,
49
+ image_cfg_scale: float = 1.5,
50
  width: int = 1024,
51
  height: int = 1024,
52
  guidance_scale: float = 6,
 
173
 
174
  with gr.Row():
175
  text_cfg_scale = gr.Number(value=7.3, step=0.1, label="Text CFG", interactive=True)
176
+ image_cfg_scale = gr.Number(value=1.5, step=0.1,label="Image CFG", interactive=True)
177
  guidance_scale = gr.Number(value=6.0, step=0.1, label="Image Generation Guidance Scale", interactive=True)
178
  steps = gr.Number(value=25, step=1, label="Steps", interactive=True)
179
  randomize_seed = gr.Radio(