gaur3009 commited on
Commit
5b9c09c
1 Parent(s): d438d47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -38
app.py CHANGED
@@ -3,12 +3,11 @@ import numpy as np
3
  import random
4
  from diffusers import DiffusionPipeline
5
  import torch
6
- from torch.fft import fftn, ifftn # For Fourier transforms
7
 
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
 
10
- # Load the model
11
  if torch.cuda.is_available():
 
12
  pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
13
  pipe.enable_xformers_memory_efficient_attention()
14
  pipe = pipe.to(device)
@@ -19,42 +18,14 @@ else:
19
  MAX_SEED = np.iinfo(np.int32).max
20
  MAX_IMAGE_SIZE = 1024
21
 
22
- # Group-theory-based seed reduction (example: cyclic group on mod N)
23
- def reduce_seeds(seed):
24
- group_size = 100 # Cyclic group of size 100
25
- return seed % group_size
26
-
27
- # Fourier-based optimization with proper tensor conversion
28
- def fft_convolution(image):
29
- # Convert the image to a PyTorch tensor
30
- tensor_image = torch.tensor(image).permute(2, 0, 1).float() # Convert to tensor and adjust channels
31
-
32
- # Convert to frequency domain using FFT
33
- freq_image = fftn(tensor_image)
34
-
35
- # Apply some transformation in the frequency domain (example: filtering, smoothing)
36
- # This is a placeholder; implement any frequency domain operation here
37
- transformed_freq_image = freq_image * torch.exp(-torch.abs(freq_image)) # Example operation
38
-
39
- # Convert back to spatial domain using inverse FFT
40
- transformed_image = ifftn(transformed_freq_image).real
41
-
42
- # Convert back to NumPy array and adjust channels back to original shape
43
- result_image = transformed_image.permute(1, 2, 0).numpy()
44
-
45
- return result_image
46
-
47
  def infer(prompt_part1, color, dress_type, design, prompt_part5, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
48
  prompt = f"{prompt_part1} {color} colored plain {dress_type} with {design} design, {prompt_part5}"
49
 
50
  if randomize_seed:
51
  seed = random.randint(0, MAX_SEED)
52
- else:
53
- seed = reduce_seeds(seed) # Apply symmetry-based seed reduction
54
 
55
  generator = torch.Generator().manual_seed(seed)
56
 
57
- # Run the diffusion model
58
  image = pipe(
59
  prompt=prompt,
60
  negative_prompt=negative_prompt,
@@ -63,13 +34,9 @@ def infer(prompt_part1, color, dress_type, design, prompt_part5, negative_prompt
63
  width=width,
64
  height=height,
65
  generator=generator
66
- ).images[0]
67
-
68
- # Apply Fourier-based convolution optimization
69
- image = np.array(image) # Convert to numpy array
70
- optimized_image = fft_convolution(image) # Apply Fourier convolution
71
-
72
- return optimized_image
73
 
74
  examples = [
75
  "red, t-shirt, yellow stripes",
@@ -143,6 +110,7 @@ with gr.Blocks(css=css) as demo:
143
  visible=False,
144
  )
145
 
 
146
  run_button = gr.Button("Run", scale=0)
147
 
148
  result = gr.Image(label="Result", show_label=False)
@@ -213,4 +181,4 @@ with gr.Blocks(css=css) as demo:
213
  outputs=[result]
214
  )
215
 
216
- demo.queue().launch()
 
3
  import random
4
  from diffusers import DiffusionPipeline
5
  import torch
 
6
 
7
  device = "cuda" if torch.cuda.is_available() else "cpu"
8
 
 
9
  if torch.cuda.is_available():
10
+ torch.cuda.max_memory_allocated(device=device)
11
  pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
12
  pipe.enable_xformers_memory_efficient_attention()
13
  pipe = pipe.to(device)
 
18
  MAX_SEED = np.iinfo(np.int32).max
19
  MAX_IMAGE_SIZE = 1024
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  def infer(prompt_part1, color, dress_type, design, prompt_part5, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
22
  prompt = f"{prompt_part1} {color} colored plain {dress_type} with {design} design, {prompt_part5}"
23
 
24
  if randomize_seed:
25
  seed = random.randint(0, MAX_SEED)
 
 
26
 
27
  generator = torch.Generator().manual_seed(seed)
28
 
 
29
  image = pipe(
30
  prompt=prompt,
31
  negative_prompt=negative_prompt,
 
34
  width=width,
35
  height=height,
36
  generator=generator
37
+ ).images[0]
38
+
39
+ return image
 
 
 
 
40
 
41
  examples = [
42
  "red, t-shirt, yellow stripes",
 
110
  visible=False,
111
  )
112
 
113
+
114
  run_button = gr.Button("Run", scale=0)
115
 
116
  result = gr.Image(label="Result", show_label=False)
 
181
  outputs=[result]
182
  )
183
 
184
+ demo.queue().launch()