prithivMLmods commited on
Commit
4bbaffd
Β·
verified Β·
1 Parent(s): 72518dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -8
app.py CHANGED
@@ -1,4 +1,3 @@
1
- import spaces
2
  import gradio as gr
3
  import torch
4
  from PIL import Image
@@ -10,7 +9,7 @@ import numpy as np
10
 
11
  def save_image(img):
12
  unique_name = str(uuid.uuid4()) + ".png"
13
- img.save(unique_name)
14
  return unique_name
15
 
16
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
@@ -26,11 +25,16 @@ if not torch.cuda.is_available():
26
  base_model = "black-forest-labs/FLUX.1-dev"
27
  pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
28
 
29
- lora_repo = "strangerzonehf/Flux-Realmix2"
30
- trigger_word = "Realmix v2" # Leave trigger_word blank if not used.
31
-
32
- pipe.load_lora_weights(lora_repo)
33
- pipe.to("cuda")
 
 
 
 
 
34
 
35
  style_list = [
36
  {
@@ -68,12 +72,20 @@ def generate(
68
  guidance_scale: float = 3,
69
  randomize_seed: bool = False,
70
  style_name: str = DEFAULT_STYLE_NAME,
 
71
  progress=gr.Progress(track_tqdm=True),
72
  ):
73
  seed = int(randomize_seed_fn(seed, randomize_seed))
74
 
75
  positive_prompt = apply_style(style_name, prompt)
76
 
 
 
 
 
 
 
 
77
  if trigger_word:
78
  positive_prompt = f"{trigger_word} {positive_prompt}"
79
 
@@ -91,7 +103,6 @@ def generate(
91
  return image_paths, seed
92
 
93
  examples = [
94
-
95
  "midjourney mix, a tiny astronaut hatching from an egg on the moon",
96
  "midjourney mix, intense Red, a black cat is facing the left side of the frame. The cats head is tilted upward, with its eyes closed. Its whiskers are protruding from its mouth, adding a touch of warmth to the scene. The background is a vibrant red, creating a striking contrast with the cats fur.",
97
  "midjourney mix, a close-up shot of a womans face, the womans hair is wet, and she is wearing a cream-colored sweater. The background is blurred, and there are red and white signs visible in the background. The womans eyebrows are wet, adding a touch of color to her face. Her lips are a vibrant shade of pink, and her eyes are a darker shade of brown.",
@@ -127,6 +138,12 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
127
  run_button = gr.Button("Generate as : ( 1280 x 832 )πŸ€—", scale=0, elem_classes="submit-btn")
128
 
129
  with gr.Accordion("Advanced options", open=True, visible=True):
 
 
 
 
 
 
130
  seed = gr.Slider(
131
  label="Seed",
132
  minimum=0,
@@ -177,6 +194,8 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
177
  value=DEFAULT_STYLE_NAME,
178
  label="Quality Style",
179
  )
 
 
180
 
181
  with gr.Column(scale=2):
182
  result = gr.Gallery(label="Result", columns=1, show_label=False)
@@ -203,6 +222,7 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
203
  guidance_scale,
204
  randomize_seed,
205
  style_selection,
 
206
  ],
207
  outputs=[result, seed],
208
  api_name="run",
 
 
1
  import gradio as gr
2
  import torch
3
  from PIL import Image
 
9
 
10
  def save_image(img):
11
  unique_name = str(uuid.uuid4()) + ".png"
12
+ img.save(unique_index)
13
  return unique_name
14
 
15
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
 
25
  base_model = "black-forest-labs/FLUX.1-dev"
26
  pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
27
 
28
+ LORA_OPTIONS = {
29
+ "Sketch-Smudge": {
30
+ "lora_repo": "strangerzonehf/Flux-Sketch-Smudge-LoRA",
31
+ "trigger_word": "Sketch Smudge"
32
+ },
33
+ "Sketch-Sized": {
34
+ "lora_repo": "strangerzonehf/Flux-Sketch-Sized-LoRA",
35
+ "trigger_word": "Sketch Sized"
36
+ }
37
+ }
38
 
39
  style_list = [
40
  {
 
72
  guidance_scale: float = 3,
73
  randomize_seed: bool = False,
74
  style_name: str = DEFAULT_STYLE_NAME,
75
+ lora_choice: str = "Sketch-Smudge",
76
  progress=gr.Progress(track_tqdm=True),
77
  ):
78
  seed = int(randomize_seed_fn(seed, randomize_seed))
79
 
80
  positive_prompt = apply_style(style_name, prompt)
81
 
82
+ # Load the selected LoRA weights
83
+ lora_repo = LORA_OPTIONS[lora_choice]["lora_repo"]
84
+ trigger_word = LORA_OPTIONS[lora_choice]["trigger_word"]
85
+
86
+ pipe.load_lora_weights(lora_repo)
87
+ pipe.to("cuda")
88
+
89
  if trigger_word:
90
  positive_prompt = f"{trigger_word} {positive_prompt}"
91
 
 
103
  return image_paths, seed
104
 
105
  examples = [
 
106
  "midjourney mix, a tiny astronaut hatching from an egg on the moon",
107
  "midjourney mix, intense Red, a black cat is facing the left side of the frame. The cats head is tilted upward, with its eyes closed. Its whiskers are protruding from its mouth, adding a touch of warmth to the scene. The background is a vibrant red, creating a striking contrast with the cats fur.",
108
  "midjourney mix, a close-up shot of a womans face, the womans hair is wet, and she is wearing a cream-colored sweater. The background is blurred, and there are red and white signs visible in the background. The womans eyebrows are wet, adding a touch of color to her face. Her lips are a vibrant shade of pink, and her eyes are a darker shade of brown.",
 
138
  run_button = gr.Button("Generate as : ( 1280 x 832 )πŸ€—", scale=0, elem_classes="submit-btn")
139
 
140
  with gr.Accordion("Advanced options", open=True, visible=True):
141
+ model_choice = gr.Dropdown(
142
+ label="LoRA Selection",
143
+ choices=list(LORA_OPTIONS.keys()),
144
+ value="Sketch-Smudge"
145
+ )
146
+
147
  seed = gr.Slider(
148
  label="Seed",
149
  minimum=0,
 
194
  value=DEFAULT_STYLE_NAME,
195
  label="Quality Style",
196
  )
197
+
198
+
199
 
200
  with gr.Column(scale=2):
201
  result = gr.Gallery(label="Result", columns=1, show_label=False)
 
222
  guidance_scale,
223
  randomize_seed,
224
  style_selection,
225
+ model_choice,
226
  ],
227
  outputs=[result, seed],
228
  api_name="run",