prithivMLmods commited on
Commit
368eb22
·
verified ·
1 Parent(s): 9ebbc57

update app

Browse files
Files changed (1) hide show
  1. app.py +36 -32
app.py CHANGED
@@ -62,16 +62,16 @@ orange_red_theme = OrangeRedTheme()
62
  MAX_SEED = np.iinfo(np.int32).max
63
 
64
  ADAPTER_SPECS = {
65
- "h4rd8are": {
66
- "repo": "siraxe/h4rd8are_klein9b",
67
- "weights": "turn_to_h4rd8are_klein9b.safetensors",
68
- "adapter_name": "h4rd8are_klein9b"
69
- },
70
  "Klein-Delight-Style": {
71
  "repo": "linoyts/Flux2-Klein-Delight-LoRA",
72
  "weights": "pytorch_lora_weights.safetensors",
73
  "adapter_name": "klein-delight"
74
- }
 
 
 
 
 
75
  }
76
 
77
  LOADED_ADAPTERS = set()
@@ -116,29 +116,33 @@ def infer(
116
  if not input_image:
117
  raise gr.Error("Please upload an image to apply a style to.")
118
 
119
- spec = ADAPTER_SPECS.get(lora_adapter)
120
- if spec:
121
- adapter_name = spec["adapter_name"]
122
-
123
- if adapter_name not in LOADED_ADAPTERS:
124
- print(f"--- Downloading and Loading Adapter: {lora_adapter} ---")
125
- try:
126
- pipe.load_lora_weights(
127
- spec["repo"],
128
- weight_name=spec["weights"],
129
- adapter_name=adapter_name
130
- )
131
- LOADED_ADAPTERS.add(adapter_name)
132
- except Exception as e:
133
- raise gr.Error(f"Failed to load adapter {lora_adapter}: {e}")
134
- else:
135
- print(f"--- Adapter {lora_adapter} is already loaded. ---")
136
-
137
- print(f"Activating LoRA: {adapter_name}")
138
- pipe.set_adapters([adapter_name], adapter_weights=[1.0])
139
- else:
140
- print("No valid LoRA selected or found. Disabling adapters.")
141
  pipe.disable_lora()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
  if randomize_seed:
144
  seed = random.randint(0, MAX_SEED)
@@ -202,7 +206,7 @@ with gr.Blocks() as demo:
202
  with gr.Row():
203
  prompt = gr.Text(
204
  label="Edit Prompt",
205
- max_lines=2,
206
  show_label=True,
207
  placeholder="e.g., a man with a red superhero mask"
208
  )
@@ -222,14 +226,14 @@ with gr.Blocks() as demo:
222
  with gr.Row():
223
  lora_adapter = gr.Dropdown(
224
  label="Choose Editing Style",
225
- choices=list(ADAPTER_SPECS.keys()),
226
  value="Klein-Delight-Style"
227
  )
228
 
229
  gr.Examples(
230
  examples=[
231
- ["examples/1.jpg", "Relight the image to remove all existing lighting conditions and replace them with neutral, uniform illumination. Apply soft, evenly distributed lighting with no directional shadows, no harsh highlights, and no dramatic contrast. Maintain the original identity of all subjects exactly—preserve facial structure, skin tone, proportions, expressions, hair, clothing, and textures. Do not alter pose, camera angle, background geometry, or image composition. Lighting should appear balanced, and studio-neutral, similar to diffuse overcast or a soft lightbox setup. Ensure consistent exposure across the entire image with realistic depth and subtle shading only where necessary for form.Relight the image to remove all existing lighting conditions and replace them with neutral, uniform illumination. Apply soft, evenly distributed lighting with no directional shadows, no harsh highlights, and no dramatic contrast. Maintain the original identity of all subjects exactly—preserve facial structure, skin tone, proportions, expressions, hair, clothing, and textures. Do not alter pose, camera angle, background geometry, or image composition. Lighting should appear balanced, and studio-neutral, similar to diffuse overcast or a soft lightbox setup. Ensure consistent exposure across the entire image with realistic depth and subtle shading only where necessary for form.", "Klein-Delight-Style"],
232
- ["examples/portrait.jpg", "cinematic lighting, high contrast", "h4rd8are"],
233
  ],
234
  inputs=[input_image, prompt, lora_adapter],
235
  outputs=[output_image, used_seed],
 
62
  MAX_SEED = np.iinfo(np.int32).max
63
 
64
  ADAPTER_SPECS = {
 
 
 
 
 
65
  "Klein-Delight-Style": {
66
  "repo": "linoyts/Flux2-Klein-Delight-LoRA",
67
  "weights": "pytorch_lora_weights.safetensors",
68
  "adapter_name": "klein-delight"
69
+ },
70
+ # "h4rd8are": {
71
+ # "repo": "siraxe/h4rd8are_klein9b",
72
+ # "weights": "turn_to_h4rd8are_klein9b.safetensors",
73
+ # "adapter_name": "h4rd8are_klein9b"
74
+ # },
75
  }
76
 
77
  LOADED_ADAPTERS = set()
 
116
  if not input_image:
117
  raise gr.Error("Please upload an image to apply a style to.")
118
 
119
+ if lora_adapter == "None":
120
+ print("Selection is None. Disabling LoRA adapters.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  pipe.disable_lora()
122
+ else:
123
+ spec = ADAPTER_SPECS.get(lora_adapter)
124
+ if spec:
125
+ adapter_name = spec["adapter_name"]
126
+
127
+ if adapter_name not in LOADED_ADAPTERS:
128
+ print(f"--- Downloading and Loading Adapter: {lora_adapter} ---")
129
+ try:
130
+ pipe.load_lora_weights(
131
+ spec["repo"],
132
+ weight_name=spec["weights"],
133
+ adapter_name=adapter_name
134
+ )
135
+ LOADED_ADAPTERS.add(adapter_name)
136
+ except Exception as e:
137
+ raise gr.Error(f"Failed to load adapter {lora_adapter}: {e}")
138
+ else:
139
+ print(f"--- Adapter {lora_adapter} is already loaded. ---")
140
+
141
+ print(f"Activating LoRA: {adapter_name}")
142
+ pipe.set_adapters([adapter_name], adapter_weights=[1.0])
143
+ else:
144
+ print("Adapter not found in specs. Disabling LoRA.")
145
+ pipe.disable_lora()
146
 
147
  if randomize_seed:
148
  seed = random.randint(0, MAX_SEED)
 
206
  with gr.Row():
207
  prompt = gr.Text(
208
  label="Edit Prompt",
209
+ max_lines=1,
210
  show_label=True,
211
  placeholder="e.g., a man with a red superhero mask"
212
  )
 
226
  with gr.Row():
227
  lora_adapter = gr.Dropdown(
228
  label="Choose Editing Style",
229
+ choices=["None"] + list(ADAPTER_SPECS.keys()),
230
  value="Klein-Delight-Style"
231
  )
232
 
233
  gr.Examples(
234
  examples=[
235
+ ["examples/1.jpg", "Relight the image to remove all existing lighting conditions and replace them with neutral, uniform illumination. Apply soft, evenly distributed lighting with no directional shadows, no harsh highlights, and no dramatic contrast. Maintain the original identity of all subjects exactly—preserve facial structure, skin tone, proportions, expressions, hair, clothing, and textures. Do not alter pose, camera angle, background geometry, or image composition. Lighting should appear balanced, and studio-neutral, similar to diffuse overcast or a soft lightbox setup. Ensure consistent exposure across the entire image with realistic depth and subtle shading only where necessary for form.", "Klein-Delight-Style"],
236
+ # ["examples/2.jpg", "Make it look cinematic", "None"],
237
  ],
238
  inputs=[input_image, prompt, lora_adapter],
239
  outputs=[output_image, used_seed],