prithivMLmods commited on
Commit
891571d
·
verified ·
1 Parent(s): 91f2272

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -8,33 +8,32 @@ import uuid
8
  from typing import Tuple
9
  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:
17
  if randomize_seed:
18
  seed = random.randint(0, MAX_SEED)
19
  return seed
20
 
 
21
  MAX_SEED = np.iinfo(np.int32).max
22
 
23
- if not torch.cuda.is_available():
24
- DESCRIPTIONz += "\n<p>⚠️Running on CPU, This may not work on CPU.</p>"
25
-
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-Super-Realism-LoRA"
30
- #trigger_word = "Super Realism" # Leave trigger_word blank if not used.
31
-
32
- lora_repo = "strangerzonehf/FallenArt-Flux"
33
- trigger_word = "Fallen Art" # Leave trigger_word blank if not used.
34
 
35
  pipe.load_lora_weights(lora_repo)
36
  pipe.to("cuda")
37
 
 
38
  style_list = [
39
  {
40
  "name": "3840 x 2160",
@@ -55,13 +54,14 @@ style_list = [
55
  ]
56
 
57
  styles = {k["name"]: k["prompt"] for k in style_list}
58
-
59
  DEFAULT_STYLE_NAME = "3840 x 2160"
60
  STYLE_NAMES = list(styles.keys())
61
 
 
62
  def apply_style(style_name: str, positive: str) -> str:
63
  return styles.get(style_name, styles[DEFAULT_STYLE_NAME]).replace("{prompt}", positive)
64
 
 
65
  @spaces.GPU(duration=60, enable_queue=True)
66
  def generate(
67
  prompt: str,
@@ -74,7 +74,6 @@ def generate(
74
  progress=gr.Progress(track_tqdm=True),
75
  ):
76
  seed = int(randomize_seed_fn(seed, randomize_seed))
77
-
78
  positive_prompt = apply_style(style_name, prompt)
79
 
80
  if trigger_word:
@@ -93,6 +92,7 @@ def generate(
93
  print(image_paths)
94
  return image_paths, seed
95
 
 
96
  examples = [
97
  "Super Realism, High-resolution photograph, woman, UHD, photorealistic, shot on a Sony A7III --chaos 20 --ar 1:2 --style raw --stylize 250",
98
  "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",
@@ -100,11 +100,17 @@ examples = [
100
  "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."
101
  ]
102
 
 
103
  css = '''
104
- .gradio-container{max-width: 888px !important}
105
- h1{text-align:center}
 
 
 
 
 
106
  footer {
107
- visibility: hidden
108
  }
109
  .submit-btn {
110
  background-color: #e34949 !important;
@@ -115,6 +121,7 @@ footer {
115
  }
116
  '''
117
 
 
118
  with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
119
  with gr.Row():
120
  with gr.Column(scale=1):
@@ -125,7 +132,7 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
125
  placeholder="Enter your prompt",
126
  container=False,
127
  )
128
- run_button = gr.Button("Generate as ( 768 x 1024 )🤗", scale=0, elem_classes="submit-btn")
129
 
130
  with gr.Accordion("Advanced options", open=True, visible=True):
131
  seed = gr.Slider(
 
8
  from typing import Tuple
9
  import numpy as np
10
 
11
+ # Function to save an image with a unique name
12
  def save_image(img):
13
  unique_name = str(uuid.uuid4()) + ".png"
14
  img.save(unique_name)
15
  return unique_name
16
 
17
+ # Function to handle seed randomization
18
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
19
  if randomize_seed:
20
  seed = random.randint(0, MAX_SEED)
21
  return seed
22
 
23
+ # Maximum seed value for 32-bit integer
24
  MAX_SEED = np.iinfo(np.int32).max
25
 
26
+ # Load the diffusion model
 
 
27
  base_model = "black-forest-labs/FLUX.1-dev"
28
  pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
29
 
30
+ lora_repo = "strangerzonehf/Flux-Super-Realism-LoRA"
31
+ trigger_word = "Super Realism" # Leave blank if not used
 
 
 
32
 
33
  pipe.load_lora_weights(lora_repo)
34
  pipe.to("cuda")
35
 
36
+ # Define style options
37
  style_list = [
38
  {
39
  "name": "3840 x 2160",
 
54
  ]
55
 
56
  styles = {k["name"]: k["prompt"] for k in style_list}
 
57
  DEFAULT_STYLE_NAME = "3840 x 2160"
58
  STYLE_NAMES = list(styles.keys())
59
 
60
+ # Apply selected style to the prompt
61
  def apply_style(style_name: str, positive: str) -> str:
62
  return styles.get(style_name, styles[DEFAULT_STYLE_NAME]).replace("{prompt}", positive)
63
 
64
+ # Image generation function with Spaces GPU support
65
  @spaces.GPU(duration=60, enable_queue=True)
66
  def generate(
67
  prompt: str,
 
74
  progress=gr.Progress(track_tqdm=True),
75
  ):
76
  seed = int(randomize_seed_fn(seed, randomize_seed))
 
77
  positive_prompt = apply_style(style_name, prompt)
78
 
79
  if trigger_word:
 
92
  print(image_paths)
93
  return image_paths, seed
94
 
95
+ # Example prompts
96
  examples = [
97
  "Super Realism, High-resolution photograph, woman, UHD, photorealistic, shot on a Sony A7III --chaos 20 --ar 1:2 --style raw --stylize 250",
98
  "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",
 
100
  "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."
101
  ]
102
 
103
+ # CSS to center the UI and style components
104
  css = '''
105
+ .gradio-container {
106
+ max-width: 888px !important;
107
+ margin: 0 auto !important;
108
+ }
109
+ h1 {
110
+ text-align: center;
111
+ }
112
  footer {
113
+ visibility: hidden;
114
  }
115
  .submit-btn {
116
  background-color: #e34949 !important;
 
121
  }
122
  '''
123
 
124
+ # Gradio interface
125
  with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
126
  with gr.Row():
127
  with gr.Column(scale=1):
 
132
  placeholder="Enter your prompt",
133
  container=False,
134
  )
135
+ run_button = gr.Button("Generate Image", scale=0, elem_classes="submit-btn")
136
 
137
  with gr.Accordion("Advanced options", open=True, visible=True):
138
  seed = gr.Slider(