Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -1,19 +1,19 @@
1
  import spaces
 
 
 
 
 
2
  import gradio as gr
3
  import numpy as np
4
- import random
5
  from diffusers import DiffusionPipeline
6
  import torch
7
  from huggingface_hub import login
8
- import os
9
 
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
11
 
12
  # Set your Hugging Face token
13
  HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
14
- if HUGGINGFACE_TOKEN is None:
15
- raise ValueError("Hugging Face token not found. Please set the HUGGINGFACE_TOKEN environment variable.")
16
-
17
  login(token=HUGGINGFACE_TOKEN)
18
 
19
  # Path to your model repository and safetensors weights
@@ -28,16 +28,11 @@ pipeline = DiffusionPipeline.from_pretrained(
28
  )
29
  pipeline.load_lora_weights(lora_weights_path)
30
 
31
- # Comment out the line for sequential CPU offloading
32
- # pipeline.enable_sequential_cpu_offload()
33
-
34
  pipeline = pipeline.to(device)
35
 
36
  MAX_SEED = np.iinfo(np.int32).max
37
  MAX_IMAGE_SIZE = 1024 # Reduce max image size to fit within memory constraints
38
 
39
- CACHE_EXAMPLES = False
40
-
41
  @spaces.GPU
42
  def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
43
  if randomize_seed:
@@ -71,6 +66,7 @@ body {
71
  margin: 0;
72
  padding: 0;
73
  }
 
74
  #header {
75
  background-color: #ff3f6c; /* Myntra's pink color */
76
  color: white;
@@ -79,6 +75,7 @@ body {
79
  font-size: 24px;
80
  font-weight: bold;
81
  }
 
82
  #col-container {
83
  margin: 0 auto;
84
  max-width: 720px;
@@ -87,6 +84,7 @@ body {
87
  border-radius: 8px;
88
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
89
  }
 
90
  .gr-button {
91
  background-color: #ff3f6c; /* Myntra's pink color */
92
  color: white;
@@ -97,17 +95,21 @@ body {
97
  cursor: pointer;
98
  margin-top: 10px;
99
  }
 
100
  .gr-button:hover {
101
  background-color: #e62e5c; /* Darker shade for hover effect */
102
  }
 
103
  .gr-textbox, .gr-slider, .gr-checkbox, .gr-accordion {
104
  margin-bottom: 20px;
105
  }
 
106
  .gr-markdown {
107
  text-align: center;
108
  font-size: 24px;
109
  margin-bottom: 20px;
110
  }
 
111
  .gr-image {
112
  border: 1px solid #ebebeb;
113
  border-radius: 8px;
@@ -194,10 +196,11 @@ with gr.Blocks(css=css) as demo:
194
  )
195
 
196
  gr.Examples(
197
- examples=examples,
198
- inputs=[prompt],
199
  outputs=[result],
200
- cache_examples=CACHE_EXAMPLES,
 
201
  )
202
 
203
  run_button.click(
 
1
  import spaces
2
+
3
+
4
+ import os
5
+ import random
6
+
7
  import gradio as gr
8
  import numpy as np
 
9
  from diffusers import DiffusionPipeline
10
  import torch
11
  from huggingface_hub import login
 
12
 
13
  device = "cuda" if torch.cuda.is_available() else "cpu"
14
 
15
  # Set your Hugging Face token
16
  HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
 
 
 
17
  login(token=HUGGINGFACE_TOKEN)
18
 
19
  # Path to your model repository and safetensors weights
 
28
  )
29
  pipeline.load_lora_weights(lora_weights_path)
30
 
 
 
 
31
  pipeline = pipeline.to(device)
32
 
33
  MAX_SEED = np.iinfo(np.int32).max
34
  MAX_IMAGE_SIZE = 1024 # Reduce max image size to fit within memory constraints
35
 
 
 
36
  @spaces.GPU
37
  def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
38
  if randomize_seed:
 
66
  margin: 0;
67
  padding: 0;
68
  }
69
+
70
  #header {
71
  background-color: #ff3f6c; /* Myntra's pink color */
72
  color: white;
 
75
  font-size: 24px;
76
  font-weight: bold;
77
  }
78
+
79
  #col-container {
80
  margin: 0 auto;
81
  max-width: 720px;
 
84
  border-radius: 8px;
85
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
86
  }
87
+
88
  .gr-button {
89
  background-color: #ff3f6c; /* Myntra's pink color */
90
  color: white;
 
95
  cursor: pointer;
96
  margin-top: 10px;
97
  }
98
+
99
  .gr-button:hover {
100
  background-color: #e62e5c; /* Darker shade for hover effect */
101
  }
102
+
103
  .gr-textbox, .gr-slider, .gr-checkbox, .gr-accordion {
104
  margin-bottom: 20px;
105
  }
106
+
107
  .gr-markdown {
108
  text-align: center;
109
  font-size: 24px;
110
  margin-bottom: 20px;
111
  }
112
+
113
  .gr-image {
114
  border: 1px solid #ebebeb;
115
  border-radius: 8px;
 
196
  )
197
 
198
  gr.Examples(
199
+ examples=examples,
200
+ inputs=[prompt],
201
  outputs=[result],
202
+ fn=infer,
203
+ cache_examples=True,
204
  )
205
 
206
  run_button.click(