prithivMLmods commited on
Commit
c35e231
·
verified ·
1 Parent(s): 8fc2985

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -21
app.py CHANGED
@@ -13,32 +13,27 @@ import zipfile
13
  DESCRIPTION = """##
14
  """
15
 
16
- # Function to save an image with a unique name
17
  def save_image(img):
18
  unique_name = str(uuid.uuid4()) + ".png"
19
  img.save(unique_name)
20
  return unique_name
21
 
22
- # Function to handle seed randomization
23
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
24
  if randomize_seed:
25
  seed = random.randint(0, MAX_SEED)
26
  return seed
27
 
28
- # Maximum seed value for 32-bit integer
29
  MAX_SEED = np.iinfo(np.int32).max
30
 
31
- # Load the diffusion model
32
  base_model = "black-forest-labs/FLUX.1-dev"
33
  pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
34
 
35
  lora_repo = "strangerzonehf/Flux-Super-Realism-LoRA"
36
- trigger_word = "Super Realism" # Leave blank if not used
37
 
38
  pipe.load_lora_weights(lora_repo)
39
  pipe.to("cuda")
40
 
41
- # Define style options with negative prompts
42
  style_list = [
43
  {
44
  "name": "3840 x 2160",
@@ -66,12 +61,10 @@ styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
66
  DEFAULT_STYLE_NAME = "3840 x 2160"
67
  STYLE_NAMES = list(styles.keys())
68
 
69
- # Apply selected style to the prompt
70
  def apply_style(style_name: str, positive: str) -> Tuple[str, str]:
71
  p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
72
  return p.replace("{prompt}", positive), n
73
 
74
- # Image generation function with Spaces GPU support
75
  @spaces.GPU(duration=60, enable_queue=True)
76
  def generate(
77
  prompt: str,
@@ -132,15 +125,13 @@ def generate(
132
 
133
  return image_paths, seed, f"{duration:.2f}", zip_path
134
 
135
- # Example prompts
136
  examples = [
137
  "Super Realism, High-resolution photograph, woman, UHD, photorealistic, shot on a Sony A7III --chaos 20 --ar 1:2 --style raw --stylize 250",
138
  "Woman in a red jacket, snowy, in the style of hyper-realistic portraiture, caninecore, mountainous vistas, timeless beauty, palewave, iconic, distinctive noses --ar 72:101 --stylize 750 --v 6",
139
- "Super Realism, Headshot of handsome young man, wearing dark gray sweater with buttons and big shawl collar, brown hair and short beard, serious look on his face, black background, soft studio lighting, portrait photography --ar 85:128 --v 6.0 --style",
140
  "Super-realism, Purple Dreamy, a medium-angle shot of a young woman with long brown hair, wearing a pair of eye-level glasses, stands in front of a backdrop of purple and white lights. The womans eyes are closed, her lips are slightly parted, as if she is looking up at the sky. Her hair is cascading over her shoulders, framing her face. She is wearing a sleeveless top, adorned with tiny white dots, and a gold chain necklace around her neck. Her left earrings are dangling from her ears, adding a pop of color to the scene."
141
  ]
142
 
143
- # CSS to center the UI and style components
144
  css = '''
145
  .gradio-container {
146
  max-width: 590px !important;
@@ -154,7 +145,6 @@ footer {
154
  }
155
  '''
156
 
157
- # Gradio interface
158
  with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
159
  gr.Markdown(DESCRIPTION)
160
  with gr.Row():
@@ -167,11 +157,9 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
167
  )
168
  run_button = gr.Button("Run", scale=0, variant="primary")
169
  result = gr.Gallery(label="Result", columns=1, show_label=False, preview=True)
170
- seed_display = gr.Textbox(label="Seed used", interactive=False)
171
- generation_time = gr.Textbox(label="Generation time (seconds)", interactive=False)
172
  zip_file = gr.File(label="Download ZIP")
173
-
174
- with gr.Accordion("Advanced options", open=False):
175
  style_selection = gr.Dropdown(
176
  label="Quality Style",
177
  choices=STYLE_NAMES,
@@ -230,7 +218,11 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
230
  value=1,
231
  )
232
  zip_images = gr.Checkbox(label="Zip generated images", value=False)
233
-
 
 
 
 
234
  gr.Examples(
235
  examples=examples,
236
  inputs=prompt,
@@ -238,16 +230,14 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
238
  fn=generate,
239
  cache_examples=False,
240
  )
241
-
242
- # Handle visibility of negative prompt
243
  use_negative_prompt.change(
244
  fn=lambda x: gr.update(visible=x),
245
  inputs=use_negative_prompt,
246
  outputs=negative_prompt,
247
  api_name=False,
248
  )
249
-
250
- # Trigger generate on prompt submit or run button click
251
  gr.on(
252
  triggers=[
253
  prompt.submit,
 
13
  DESCRIPTION = """##
14
  """
15
 
 
16
  def save_image(img):
17
  unique_name = str(uuid.uuid4()) + ".png"
18
  img.save(unique_name)
19
  return unique_name
20
 
 
21
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
22
  if randomize_seed:
23
  seed = random.randint(0, MAX_SEED)
24
  return seed
25
 
 
26
  MAX_SEED = np.iinfo(np.int32).max
27
 
 
28
  base_model = "black-forest-labs/FLUX.1-dev"
29
  pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
30
 
31
  lora_repo = "strangerzonehf/Flux-Super-Realism-LoRA"
32
+ trigger_word = "Super Realism"
33
 
34
  pipe.load_lora_weights(lora_repo)
35
  pipe.to("cuda")
36
 
 
37
  style_list = [
38
  {
39
  "name": "3840 x 2160",
 
61
  DEFAULT_STYLE_NAME = "3840 x 2160"
62
  STYLE_NAMES = list(styles.keys())
63
 
 
64
  def apply_style(style_name: str, positive: str) -> Tuple[str, str]:
65
  p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
66
  return p.replace("{prompt}", positive), n
67
 
 
68
  @spaces.GPU(duration=60, enable_queue=True)
69
  def generate(
70
  prompt: str,
 
125
 
126
  return image_paths, seed, f"{duration:.2f}", zip_path
127
 
 
128
  examples = [
129
  "Super Realism, High-resolution photograph, woman, UHD, photorealistic, shot on a Sony A7III --chaos 20 --ar 1:2 --style raw --stylize 250",
130
  "Woman in a red jacket, snowy, in the style of hyper-realistic portraiture, caninecore, mountainous vistas, timeless beauty, palewave, iconic, distinctive noses --ar 72:101 --stylize 750 --v 6",
131
+ "Super Realism, Headshot of handsome young man, wearing dark gray sweater with buttons and big shawl collar, brown hair and short beard, serious look on his face, black background, soft studio lighting, portrait ONE photography --ar 85:128 --v 6.0 --style",
132
  "Super-realism, Purple Dreamy, a medium-angle shot of a young woman with long brown hair, wearing a pair of eye-level glasses, stands in front of a backdrop of purple and white lights. The womans eyes are closed, her lips are slightly parted, as if she is looking up at the sky. Her hair is cascading over her shoulders, framing her face. She is wearing a sleeveless top, adorned with tiny white dots, and a gold chain necklace around her neck. Her left earrings are dangling from her ears, adding a pop of color to the scene."
133
  ]
134
 
 
135
  css = '''
136
  .gradio-container {
137
  max-width: 590px !important;
 
145
  }
146
  '''
147
 
 
148
  with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
149
  gr.Markdown(DESCRIPTION)
150
  with gr.Row():
 
157
  )
158
  run_button = gr.Button("Run", scale=0, variant="primary")
159
  result = gr.Gallery(label="Result", columns=1, show_label=False, preview=True)
 
 
160
  zip_file = gr.File(label="Download ZIP")
161
+
162
+ with gr.Accordion("Additional Options", open=False):
163
  style_selection = gr.Dropdown(
164
  label="Quality Style",
165
  choices=STYLE_NAMES,
 
218
  value=1,
219
  )
220
  zip_images = gr.Checkbox(label="Zip generated images", value=False)
221
+
222
+ gr.Markdown("### Output Information")
223
+ seed_display = gr.Textbox(label="Seed used", interactive=False)
224
+ generation_time = gr.Textbox(label="Generation time (seconds)", interactive=False)
225
+
226
  gr.Examples(
227
  examples=examples,
228
  inputs=prompt,
 
230
  fn=generate,
231
  cache_examples=False,
232
  )
233
+
 
234
  use_negative_prompt.change(
235
  fn=lambda x: gr.update(visible=x),
236
  inputs=use_negative_prompt,
237
  outputs=negative_prompt,
238
  api_name=False,
239
  )
240
+
 
241
  gr.on(
242
  triggers=[
243
  prompt.submit,