Aure3D commited on
Commit
c0f6332
·
verified ·
1 Parent(s): eb9e5d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -1,27 +1,26 @@
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
-
5
- # import spaces #[uncomment to use ZeroGPU]
6
- from diffusers import DiffusionPipeline
7
  import torch
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
- model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
 
11
 
12
- if torch.cuda.is_available():
13
- torch_dtype = torch.float16
14
- else:
15
- torch_dtype = torch.float32
16
 
 
17
  pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
18
  pipe = pipe.to(device)
19
 
 
 
 
20
  MAX_SEED = np.iinfo(np.int32).max
21
  MAX_IMAGE_SIZE = 1024
22
 
23
-
24
- # @spaces.GPU #[uncomment to use ZeroGPU]
25
  def infer(
26
  prompt,
27
  negative_prompt,
@@ -36,7 +35,7 @@ def infer(
36
  if randomize_seed:
37
  seed = random.randint(0, MAX_SEED)
38
 
39
- generator = torch.Generator().manual_seed(seed)
40
 
41
  image = pipe(
42
  prompt=prompt,
@@ -52,9 +51,9 @@ def infer(
52
 
53
 
54
  examples = [
55
- "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
56
- "An astronaut riding a green horse",
57
- "A delicious ceviche cheesecake slice",
58
  ]
59
 
60
  css = """
@@ -66,7 +65,7 @@ css = """
66
 
67
  with gr.Blocks(css=css) as demo:
68
  with gr.Column(elem_id="col-container"):
69
- gr.Markdown(" # Text-to-Image Gradio Template")
70
 
71
  with gr.Row():
72
  prompt = gr.Text(
@@ -105,7 +104,7 @@ with gr.Blocks(css=css) as demo:
105
  minimum=256,
106
  maximum=MAX_IMAGE_SIZE,
107
  step=32,
108
- value=1024, # Replace with defaults that work for your model
109
  )
110
 
111
  height = gr.Slider(
@@ -113,7 +112,7 @@ with gr.Blocks(css=css) as demo:
113
  minimum=256,
114
  maximum=MAX_IMAGE_SIZE,
115
  step=32,
116
- value=1024, # Replace with defaults that work for your model
117
  )
118
 
119
  with gr.Row():
@@ -122,7 +121,7 @@ with gr.Blocks(css=css) as demo:
122
  minimum=0.0,
123
  maximum=10.0,
124
  step=0.1,
125
- value=0.0, # Replace with defaults that work for your model
126
  )
127
 
128
  num_inference_steps = gr.Slider(
@@ -130,10 +129,11 @@ with gr.Blocks(css=css) as demo:
130
  minimum=1,
131
  maximum=50,
132
  step=1,
133
- value=2, # Replace with defaults that work for your model
134
  )
135
 
136
  gr.Examples(examples=examples, inputs=[prompt])
 
137
  gr.on(
138
  triggers=[run_button.click, prompt.submit],
139
  fn=infer,
 
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
+ from diffusers import DiffusionPipeline, LoRA
 
 
5
  import torch
6
 
7
  device = "cuda" if torch.cuda.is_available() else "cpu"
8
+ model_repo_id = "stabilityai/sdxl-turbo" # Replace with the base model you want to use
9
+ lora_path = "lora.safetensors" # Path to your LoRA model
10
 
11
+ # Set appropriate torch dtype
12
+ torch_dtype = torch.float16 if device == "cuda" else torch.float32
 
 
13
 
14
+ # Load base pipeline
15
  pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
16
  pipe = pipe.to(device)
17
 
18
+ # Load and apply LoRA
19
+ pipe.load_lora_weights(lora_path)
20
+
21
  MAX_SEED = np.iinfo(np.int32).max
22
  MAX_IMAGE_SIZE = 1024
23
 
 
 
24
  def infer(
25
  prompt,
26
  negative_prompt,
 
35
  if randomize_seed:
36
  seed = random.randint(0, MAX_SEED)
37
 
38
+ generator = torch.Generator(device).manual_seed(seed)
39
 
40
  image = pipe(
41
  prompt=prompt,
 
51
 
52
 
53
  examples = [
54
+ "Emoji of a smiling face with sunglasses, colorful background, 8k",
55
+ "An emoji riding a green horse",
56
+ "A delicious emoji-themed cheesecake",
57
  ]
58
 
59
  css = """
 
65
 
66
  with gr.Blocks(css=css) as demo:
67
  with gr.Column(elem_id="col-container"):
68
+ gr.Markdown(" # Text-to-Image Gradio Template with LoRA")
69
 
70
  with gr.Row():
71
  prompt = gr.Text(
 
104
  minimum=256,
105
  maximum=MAX_IMAGE_SIZE,
106
  step=32,
107
+ value=1024,
108
  )
109
 
110
  height = gr.Slider(
 
112
  minimum=256,
113
  maximum=MAX_IMAGE_SIZE,
114
  step=32,
115
+ value=1024,
116
  )
117
 
118
  with gr.Row():
 
121
  minimum=0.0,
122
  maximum=10.0,
123
  step=0.1,
124
+ value=7.5,
125
  )
126
 
127
  num_inference_steps = gr.Slider(
 
129
  minimum=1,
130
  maximum=50,
131
  step=1,
132
+ value=25,
133
  )
134
 
135
  gr.Examples(examples=examples, inputs=[prompt])
136
+
137
  gr.on(
138
  triggers=[run_button.click, prompt.submit],
139
  fn=infer,