ford442 commited on
Commit
cbb6aa4
·
verified ·
1 Parent(s): a6cc27f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -281
app.py CHANGED
@@ -4,78 +4,16 @@
4
  # in the Software without restriction, including without limitation the rights
5
  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6
  # copies of the Software, and to permit persons to whom the Software is
7
- import spaces
8
- import os
9
- import subprocess
10
- import re
11
 
12
  #subprocess.run(['sh', './torch.sh'])
13
 
14
- #import sys
15
- #conda_prefix = os.path.expanduser("~/miniconda3")
16
- #conda_bin = os.path.join(conda_prefix, "bin")
17
-
18
- # Add Conda's bin directory to your PATH
19
- #os.environ["PATH"] = conda_bin + os.pathsep + os.environ["PATH"]
20
-
21
- # Activate the base environment (adjust if needed)
22
- #os.system(f'{conda_bin}/conda init --all')
23
- #os.system(f'{conda_bin}/conda activate base')
24
-
25
-
26
- #os.system(f'{conda_bin}/conda install nvidia/label/cudnn-9.3.0::cudnn')
27
- #os.system(f'{conda_bin}/conda install nvidia/label/cuda-12.4.0::cuda-libraries')
28
- #os.system(f'{conda_bin}/conda install nvidia/label/cuda-12.4.0::cuda-libraries-dev')
29
- #os.system(f'{conda_bin}/conda install nvidia/label/cuda-12.4.0::cuda-cudart')
30
- #os.system(f'{conda_bin}/conda install nvidia/label/cuda-12.4.0::cuda-cudart-dev')
31
- #os.system(f'{conda_bin}/conda install nvidia/label/cuda-12.4.0::cuda-nvcc')
32
-
33
- #os.system(f'{conda_bin}/conda install nvidia/label/cuda-12.4.0::cuda-toolkit')
34
-
35
- #subprocess.run(['pip', 'install', 'git+https://github.com/hidet-org/hidet.git'])
36
- #subprocess.run(['pip', 'install', 'git+https://github.com/ford442/hidet.git@thread'])
37
-
38
- #os.system(f'{conda_bin}/conda install pytorch::pytorch-cuda')
39
- #os.system(f'{conda_bin}/conda install rcdr_py37::tensorrt')
40
- #subprocess.run(['sh', './hidet.sh'])
41
- #subprocess.run(['sh', './modelopt.sh'])
42
- #import hidet
43
- #print(dir(hidet))
44
- #import torch_tensorrt
45
-
46
- import random
47
- import uuid
48
  import gradio as gr
49
  import numpy as np
50
  from PIL import Image
51
 
52
- import diffusers
53
- from diffusers import AutoencoderKL, StableDiffusionXLPipeline
54
- from diffusers import EulerAncestralDiscreteScheduler
55
- from typing import Tuple
56
- import paramiko
57
- import datetime
58
  import cyper
59
- from image_gen_aux import UpscaleWithModel
60
- import torch
61
- #import torch._dynamo
62
- #torch._dynamo.list_backends()
63
- import time
64
- import gc
65
-
66
- import torch.nn.functional as F
67
- from sageattention import sageattn
68
-
69
- torch.backends.cuda.matmul.allow_tf32 = False
70
- torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
71
- torch.backends.cuda.matmul.allow_fp16_reduced_precision_reduction = False
72
- torch.backends.cudnn.allow_tf32 = False
73
- torch.backends.cudnn.deterministic = False
74
- torch.backends.cudnn.benchmark = False
75
- # torch.backends.cuda.preferred_blas_library="cublas"
76
- # torch.backends.cuda.preferred_linalg_library="cusolver"
77
- torch.set_float32_matmul_precision("highest")
78
-
79
 
80
  DESCRIPTIONXX = """
81
  ## ⚡⚡⚡⚡ REALVISXL V5.0 BF16 (Tester C) ⚡⚡⚡⚡
@@ -119,135 +57,9 @@ style_list = [
119
  styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
120
  DEFAULT_STYLE_NAME = "Style Zero"
121
  STYLE_NAMES = list(styles.keys())
122
- HF_TOKEN = os.getenv("HF_TOKEN")
123
- FTP_HOST = os.getenv("FTP_HOST")
124
- FTP_USER = os.getenv("FTP_USER")
125
- FTP_PASS = os.getenv("FTP_PASS")
126
- FTP_DIR = os.getenv("FTP_DIR")
127
 
128
  # os.putenv('TORCH_LINALG_PREFER_CUSOLVER','1')
129
 
130
- def scheduler_swap_callback(pipeline, step_index, timestep, callback_kwargs):
131
- # adjust the batch_size of prompt_embeds according to guidance_scale
132
- if step_index == int(pipeline.num_timesteps * 0.1):
133
- print("-- swapping scheduler --")
134
- # pipeline.scheduler = euler_scheduler
135
- torch.set_float32_matmul_precision("high")
136
- # pipe.vae = vae_b
137
- torch.backends.cudnn.allow_tf32 = True
138
- torch.backends.cuda.matmul.allow_tf32 = True
139
- torch.backends.cudnn.deterministic = True
140
- torch.backends.cuda.preferred_blas_library="cublaslt"
141
- #if step_index == int(pipeline.num_timesteps * 0.5):
142
- # torch.set_float32_matmul_precision("medium")
143
- #callback_kwargs["latents"] = callback_kwargs["latents"].to(torch.float64)
144
- #pipe.unet.to(torch.float64)
145
- # pipe.guidance_scale=1.0
146
- # pipe.scheduler.set_timesteps(num_inference_steps*.70)
147
- # print(f"-- setting step {pipeline.num_timesteps * 0.1} --")
148
- # pipeline.scheduler._step_index = pipeline.num_timesteps * 0.1
149
- if step_index == int(pipeline.num_timesteps * 0.9):
150
- torch.backends.cuda.preferred_blas_library="cublas"
151
- torch.backends.cudnn.allow_tf32 = False
152
- torch.backends.cuda.matmul.allow_tf32 = False
153
- torch.set_float32_matmul_precision("highest")
154
- #callback_kwargs["latents"] = callback_kwargs["latents"].to(torch.bfloat16)
155
- #pipe.unet.to(torch.float64)
156
- # pipe.vae = vae_a
157
- # pipe.unet = unet_a
158
- torch.backends.cudnn.deterministic = False
159
- #pipe.unet.set_default_attn_processor()
160
- print("-- swapping scheduler --")
161
- # pipeline.scheduler = heun_scheduler
162
- #pipe.scheduler.set_timesteps(num_inference_steps*.70)
163
- # print(f"-- setting step {pipeline.num_timesteps * 0.9} --")
164
- # pipeline.scheduler._step_index = pipeline.num_timesteps * 0.9
165
- return {"latents": callback_kwargs["latents"]}
166
-
167
- '''
168
- os.putenv('HF_HUB_ENABLE_HF_TRANSFER','1')
169
- device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
170
- os.environ["SAFETENSORS_FAST_GPU"] = "1"
171
-
172
- upscaler = UpscaleWithModel.from_pretrained("Kim2091/ClearRealityV1").to(torch.device("cuda:0"))
173
-
174
- def load_and_prepare_model():
175
- sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler',beta_schedule="scaled_linear", beta_start=0.00085, beta_end=0.012, steps_offset=1 ,use_karras_sigmas=True)
176
- vaeXL = AutoencoderKL.from_pretrained("stabilityai/sdxl-vae", safety_checker=None, use_safetensors=False, device_map='cpu') #.to(torch.bfloat16) #.to(device=device, dtype=torch.bfloat16)
177
- #vaeRV = AutoencoderKL.from_pretrained("SG161222/RealVisXL_V5.0", subfolder='vae', safety_checker=None, use_safetensors=False).to(device).to(torch.bfloat16) #.to(device=device, dtype=torch.bfloat16)
178
- #sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler',beta_schedule="scaled_linear")
179
- #txt_1 = CLIPTextModel.from_pretrained(device_map??)
180
- #txt_2 = CLIPTextModel.from_pretrained(vae too?)
181
- #sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler')
182
- pipe = StableDiffusionXLPipeline.from_pretrained(
183
- 'ford442/RealVisXL_V5.0_BF16',
184
- #torch_dtype=torch.bfloat16,
185
- add_watermarker=False,
186
- # low_cpu_mem_usage = False,
187
- token = HF_TOKEN,
188
- # scheduler = sched,
189
- )
190
- #sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler',beta_schedule="scaled_linear", beta_start=0.00085, beta_end=0.012, steps_offset=1) #,use_karras_sigmas=True)
191
- pipe.vae = vaeXL #.to(torch.bfloat16)
192
- pipe.scheduler = sched
193
-
194
- pipe.vae.do_resize = False
195
- #pipe.vae.vae_scale_factor = 8
196
- pipe.vae.do_convert_rgb = True
197
-
198
- pipe.vae.set_default_attn_processor()
199
- #pipe.to(device)
200
- #pipe.to(torch.bfloat16)
201
- print(f'init noise scale: {pipe.scheduler.init_noise_sigma}')
202
- pipe.watermark=None
203
- pipe.safety_checker=None
204
-
205
- ''' ''' # Freeze vae and unet
206
- pipe.vae.requires_grad_(False)
207
- pipe.unet.requires_grad_(False)
208
- pipe.text_encoder.requires_grad_(False)
209
- pipe.unet.eval()
210
- pipe.vae.eval()
211
- pipe.text_encoder.eval()
212
- ''' '''
213
- #pipe.unet = pipe.unet.to(memory_format=torch.contiguous_format)
214
- #pipe.load_lora_weights("ford442/sdxl-vae-bf16", weight_name="LoRA/FLUX-dev-lora-add_details.safetensors", low_cpu_mem_usage=False)
215
- #pipe.unet.to(memory_format=torch.channels_last)
216
- #pipe.enable_vae_tiling()
217
- #pipe.unet = torch.compile(pipe.unet, backend="hidet", dynamic=False, mode='max-autotune') #.to(device=device, dtype=torch.bfloat16)
218
- #pipe.unet = torch.compile(pipe.unet, backend="hidet", dynamic=False, mode='max-autotune-no-cudagraphs') #.to(device=device, dtype=torch.bfloat16)
219
- #pipe.unet = torch.compile(pipe.unet, backend="hidet", dynamic=False, options={'epilogue_fusion': True, 'shape_padding': True}) #.to(device=device, dtype=torch.bfloat16)
220
- #pipe.unet = torch.compile(pipe.unet, dynamic=False)
221
- #pipe.unet = torch.compile(pipe.unet, backend="hidet", dynamic=False, options={"search_space": 0})
222
- #pipe.unet = torch.compile(pipe.unet, backend="torch_tensorrt", dynamic=False, options={"precision": torch.bfloat16,"optimization_level": 4,})
223
- pipe.to(torch.device('cuda:0'), torch.bfloat16)
224
-
225
- return pipe
226
-
227
- #hidet.option.parallel_build(False)
228
- #hidet.option.parallel_tune(2,2.0)
229
- #torch._dynamo.config.suppress_errors = True
230
- #torch._dynamo.disallow_in_graph(diffusers.models.attention.BasicTransformerBlock)
231
-
232
- # more search
233
- #hidet.torch.dynamo_config.search_space(0)
234
- #hidet.torch.dynamo_config.dump_graph_ir("./local_graph")
235
- # hidet.option.cache_dir("local_cache")
236
- # automatically transform the model to use float16 data type
237
- #hidet.torch.dynamo_config.use_fp16(True)
238
- # use float16 data type as the accumulate data type in operators with reduction
239
- #hidet.torch.dynamo_config.use_fp16_reduction(True)
240
- # use tensorcore
241
- #hidet.torch.dynamo_config.use_tensor_core()
242
- #hidet.torch.dynamo_config.steal_weights(False)
243
-
244
- # Preload and compile both models
245
-
246
- pipe = load_and_prepare_model()
247
- neg_prompt_2 = " 'non-photorealistic':1.5, 'unrealistic skin','unattractive face':1.3, 'low quality':1.1, ('dull color scheme', 'dull colors', 'digital noise':1.2),'amateurish', 'poorly drawn face':1.3, 'poorly drawn', 'distorted face', 'low resolution', 'simplistic' "
248
-
249
- '''
250
-
251
  MAX_SEED = np.iinfo(np.int64).max
252
 
253
  def upload_to_ftp(filename):
@@ -283,6 +95,16 @@ import torch
283
  import paramiko
284
  import os
285
 
 
 
 
 
 
 
 
 
 
 
286
  HF_TOKEN = os.getenv("HF_TOKEN")
287
 
288
  FTP_HOST = os.getenv("FTP_HOST")
@@ -429,9 +251,8 @@ def load_and_prepare_model():
429
  pipe = load_and_prepare_model()
430
  neg_prompt_2 = " 'non-photorealistic':1.5, 'unrealistic skin','unattractive face':1.3, 'low quality':1.1, ('dull color scheme', 'dull colors', 'digital noise':1.2),'amateurish', 'poorly drawn face':1.3, 'poorly drawn', 'distorted face', 'low resolution', 'simplistic' "
431
 
432
-
433
  @spaces.GPU(duration=40)
434
- def generate_30c(
435
  prompt: str,
436
  negative_prompt: str = "",
437
  use_negative_prompt: bool = False,
@@ -483,12 +304,9 @@ def generate_30c(
483
  unique_name = str(uuid.uuid4()) + ".png"
484
  os.symlink(sd_image_path, unique_name)
485
  return [unique_name]
486
-
487
- '''
488
- pyx = cyper.inline(code, fast_indexing=True, directives=dict(boundscheck=False, wraparound=False, language_level=3))
489
 
490
- @spaces.GPU(duration=40)
491
- def generate_30(
492
  prompt: str,
493
  negative_prompt: str = "",
494
  use_negative_prompt: bool = False,
@@ -517,75 +335,26 @@ def generate_30(
517
  "num_inference_steps": num_inference_steps,
518
  "generator": generator,
519
  "output_type": "pil",
520
- "callback_on_step_end": pyx.scheduler_swap_callback,
521
  }
522
  if use_resolution_binning:
523
  options["use_resolution_binning"] = True
524
  images = []
525
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
526
- filename = pyx.uploadNote(prompt,num_inference_steps,guidance_scale,timestamp)
527
- pyx.upload_to_ftp(filename)
528
  batch_options = options.copy()
529
  rv_image = pipe(**batch_options).images[0]
530
  sd_image_path = f"rv_C_{timestamp}.png"
531
  rv_image.save(sd_image_path,optimize=False,compress_level=0)
532
- pyx.upload_to_ftp(sd_image_path)
533
  torch.set_float32_matmul_precision("medium")
534
  with torch.no_grad():
535
  upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
536
  downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
537
  downscale_path = f"rv50_upscale_{timestamp}.png"
538
  downscale1.save(downscale_path,optimize=False,compress_level=0)
539
- pyx.upload_to_ftp(downscale_path)
540
- unique_name = str(uuid.uuid4()) + ".png"
541
- os.symlink(sd_image_path, unique_name)
542
- return [unique_name]
543
-
544
- @spaces.GPU(duration=70)
545
- def generate_60(
546
- prompt: str,
547
- negative_prompt: str = "",
548
- use_negative_prompt: bool = False,
549
- style_selection: str = "",
550
- width: int = 768,
551
- height: int = 768,
552
- guidance_scale: float = 4,
553
- num_inference_steps: int = 125,
554
- sage: bool = False,
555
- use_resolution_binning: bool = True,
556
- progress=gr.Progress(track_tqdm=True)
557
- ):
558
- if sage==True:
559
- F.scaled_dot_product_attention = sageattn
560
- if sage==False:
561
- F.scaled_dot_product_attention = F.scaled_dot_product_attention
562
- seed = random.randint(0, MAX_SEED)
563
- generator = torch.Generator(device='cuda').manual_seed(seed)
564
- options = {
565
- "prompt": [prompt],
566
- "negative_prompt": [negative_prompt],
567
- "negative_prompt_2": [neg_prompt_2],
568
- "width": width,
569
- "height": height,
570
- "guidance_scale": guidance_scale,
571
- "num_inference_steps": num_inference_steps,
572
- "generator": generator,
573
- "output_type": "pil",
574
- "callback_on_step_end": pyx.scheduler_swap_callback,
575
- }
576
- if use_resolution_binning:
577
- options["use_resolution_binning"] = True
578
- images = []
579
- timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
580
- uploadNote(prompt,num_inference_steps,guidance_scale,timestamp)
581
- batch_options = options.copy()
582
- gc.collect()
583
- torch.cuda.empty_cache()
584
- time.sleep(2)
585
- rv_image = pipe(**batch_options).images[0]
586
- sd_image_path = f"rv_C_{timestamp}.png"
587
- rv_image.save(sd_image_path,optimize=False,compress_level=0)
588
- upload_to_ftp(sd_image_path)
589
  unique_name = str(uuid.uuid4()) + ".png"
590
  os.symlink(sd_image_path, unique_name)
591
  return [unique_name]
@@ -620,25 +389,33 @@ def generate_90(
620
  "num_inference_steps": num_inference_steps,
621
  "generator": generator,
622
  "output_type": "pil",
623
- "callback_on_step_end": pyx.scheduler_swap_callback,
624
  }
625
  if use_resolution_binning:
626
  options["use_resolution_binning"] = True
627
  images = []
628
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
629
- uploadNote(prompt,num_inference_steps,guidance_scale,timestamp)
 
630
  batch_options = options.copy()
631
- gc.collect()
632
- torch.cuda.empty_cache()
633
- time.sleep(2)
634
  rv_image = pipe(**batch_options).images[0]
635
  sd_image_path = f"rv_C_{timestamp}.png"
636
  rv_image.save(sd_image_path,optimize=False,compress_level=0)
637
  upload_to_ftp(sd_image_path)
 
 
 
 
 
 
 
638
  unique_name = str(uuid.uuid4()) + ".png"
639
  os.symlink(sd_image_path, unique_name)
640
  return [unique_name]
641
 
 
 
 
642
  def load_predefined_images1():
643
  predefined_images1 = [
644
  "assets/7.png",
@@ -677,7 +454,6 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
677
  placeholder="Enter your prompt",
678
  container=False,
679
  )
680
- run_button_30c = gr.Button("Run 30 Seconds", scale=0)
681
  run_button_30 = gr.Button("Run 30 Seconds", scale=0)
682
  run_button_60 = gr.Button("Run 60 Seconds", scale=0)
683
  run_button_90 = gr.Button("Run 90 Seconds", scale=0)
@@ -756,33 +532,13 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
756
  outputs=negative_prompt,
757
  api_name=False,
758
  )
759
-
760
- gr.on(
761
- triggers=[
762
- run_button_30c.click,
763
- ],
764
- # api_name="generate", # Add this line
765
- fn=pyx.generate_30c,
766
- inputs=[
767
- prompt,
768
- negative_prompt,
769
- use_negative_prompt,
770
- style_selection,
771
- width,
772
- height,
773
- guidance_scale,
774
- num_inference_steps,
775
- sage,
776
- ],
777
- outputs=[result],
778
- )
779
-
780
  gr.on(
781
  triggers=[
782
  run_button_30.click,
783
  ],
784
  # api_name="generate", # Add this line
785
- fn=generate_30,
786
  inputs=[
787
  prompt,
788
  negative_prompt,
@@ -802,7 +558,7 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
802
  run_button_60.click,
803
  ],
804
  # api_name="generate", # Add this line
805
- fn=generate_60,
806
  inputs=[
807
  prompt,
808
  negative_prompt,
@@ -822,7 +578,7 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
822
  run_button_90.click,
823
  ],
824
  # api_name="generate", # Add this line
825
- fn=generate_90,
826
  inputs=[
827
  prompt,
828
  negative_prompt,
 
4
  # in the Software without restriction, including without limitation the rights
5
  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6
  # copies of the Software, and to permit persons to whom the Software is
7
+ #import spaces
8
+ #import subprocess
 
 
9
 
10
  #subprocess.run(['sh', './torch.sh'])
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  import gradio as gr
13
  import numpy as np
14
  from PIL import Image
15
 
 
 
 
 
 
 
16
  import cyper
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  DESCRIPTIONXX = """
19
  ## ⚡⚡⚡⚡ REALVISXL V5.0 BF16 (Tester C) ⚡⚡⚡⚡
 
57
  styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
58
  DEFAULT_STYLE_NAME = "Style Zero"
59
  STYLE_NAMES = list(styles.keys())
 
 
 
 
 
60
 
61
  # os.putenv('TORCH_LINALG_PREFER_CUSOLVER','1')
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  MAX_SEED = np.iinfo(np.int64).max
64
 
65
  def upload_to_ftp(filename):
 
95
  import paramiko
96
  import os
97
 
98
+ torch.backends.cuda.matmul.allow_tf32 = False
99
+ torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
100
+ torch.backends.cuda.matmul.allow_fp16_reduced_precision_reduction = False
101
+ torch.backends.cudnn.allow_tf32 = False
102
+ torch.backends.cudnn.deterministic = False
103
+ torch.backends.cudnn.benchmark = False
104
+ # torch.backends.cuda.preferred_blas_library="cublas"
105
+ # torch.backends.cuda.preferred_linalg_library="cusolver"
106
+ torch.set_float32_matmul_precision("highest")
107
+
108
  HF_TOKEN = os.getenv("HF_TOKEN")
109
 
110
  FTP_HOST = os.getenv("FTP_HOST")
 
251
  pipe = load_and_prepare_model()
252
  neg_prompt_2 = " 'non-photorealistic':1.5, 'unrealistic skin','unattractive face':1.3, 'low quality':1.1, ('dull color scheme', 'dull colors', 'digital noise':1.2),'amateurish', 'poorly drawn face':1.3, 'poorly drawn', 'distorted face', 'low resolution', 'simplistic' "
253
 
 
254
  @spaces.GPU(duration=40)
255
+ def generate_30(
256
  prompt: str,
257
  negative_prompt: str = "",
258
  use_negative_prompt: bool = False,
 
304
  unique_name = str(uuid.uuid4()) + ".png"
305
  os.symlink(sd_image_path, unique_name)
306
  return [unique_name]
 
 
 
307
 
308
+ @spaces.GPU(duration=70)
309
+ def generate_60(
310
  prompt: str,
311
  negative_prompt: str = "",
312
  use_negative_prompt: bool = False,
 
335
  "num_inference_steps": num_inference_steps,
336
  "generator": generator,
337
  "output_type": "pil",
338
+ "callback_on_step_end": scheduler_swap_callback,
339
  }
340
  if use_resolution_binning:
341
  options["use_resolution_binning"] = True
342
  images = []
343
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
344
+ filename = uploadNote(prompt,num_inference_steps,guidance_scale,timestamp)
345
+ upload_to_ftp(filename)
346
  batch_options = options.copy()
347
  rv_image = pipe(**batch_options).images[0]
348
  sd_image_path = f"rv_C_{timestamp}.png"
349
  rv_image.save(sd_image_path,optimize=False,compress_level=0)
350
+ upload_to_ftp(sd_image_path)
351
  torch.set_float32_matmul_precision("medium")
352
  with torch.no_grad():
353
  upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
354
  downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
355
  downscale_path = f"rv50_upscale_{timestamp}.png"
356
  downscale1.save(downscale_path,optimize=False,compress_level=0)
357
+ upload_to_ftp(downscale_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  unique_name = str(uuid.uuid4()) + ".png"
359
  os.symlink(sd_image_path, unique_name)
360
  return [unique_name]
 
389
  "num_inference_steps": num_inference_steps,
390
  "generator": generator,
391
  "output_type": "pil",
392
+ "callback_on_step_end": scheduler_swap_callback,
393
  }
394
  if use_resolution_binning:
395
  options["use_resolution_binning"] = True
396
  images = []
397
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
398
+ filename = uploadNote(prompt,num_inference_steps,guidance_scale,timestamp)
399
+ upload_to_ftp(filename)
400
  batch_options = options.copy()
 
 
 
401
  rv_image = pipe(**batch_options).images[0]
402
  sd_image_path = f"rv_C_{timestamp}.png"
403
  rv_image.save(sd_image_path,optimize=False,compress_level=0)
404
  upload_to_ftp(sd_image_path)
405
+ torch.set_float32_matmul_precision("medium")
406
+ with torch.no_grad():
407
+ upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
408
+ downscale1 = upscale.resize((upscale.width // 4, upscale.height // 4), Image.LANCZOS)
409
+ downscale_path = f"rv50_upscale_{timestamp}.png"
410
+ downscale1.save(downscale_path,optimize=False,compress_level=0)
411
+ upload_to_ftp(downscale_path)
412
  unique_name = str(uuid.uuid4()) + ".png"
413
  os.symlink(sd_image_path, unique_name)
414
  return [unique_name]
415
 
416
+ '''
417
+ pyx = cyper.inline(code, fast_indexing=True, directives=dict(boundscheck=False, wraparound=False, language_level=3))
418
+
419
  def load_predefined_images1():
420
  predefined_images1 = [
421
  "assets/7.png",
 
454
  placeholder="Enter your prompt",
455
  container=False,
456
  )
 
457
  run_button_30 = gr.Button("Run 30 Seconds", scale=0)
458
  run_button_60 = gr.Button("Run 60 Seconds", scale=0)
459
  run_button_90 = gr.Button("Run 90 Seconds", scale=0)
 
532
  outputs=negative_prompt,
533
  api_name=False,
534
  )
535
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
536
  gr.on(
537
  triggers=[
538
  run_button_30.click,
539
  ],
540
  # api_name="generate", # Add this line
541
+ fn=pyx.generate_30,
542
  inputs=[
543
  prompt,
544
  negative_prompt,
 
558
  run_button_60.click,
559
  ],
560
  # api_name="generate", # Add this line
561
+ fn=pyx.generate_60,
562
  inputs=[
563
  prompt,
564
  negative_prompt,
 
578
  run_button_90.click,
579
  ],
580
  # api_name="generate", # Add this line
581
+ fn=pyx.generate_90,
582
  inputs=[
583
  prompt,
584
  negative_prompt,