prithivMLmods commited on
Commit
0fa3c41
·
verified ·
1 Parent(s): bd85747

update app

Browse files
Files changed (1) hide show
  1. app.py +23 -32
app.py CHANGED
@@ -99,19 +99,15 @@ if torch.cuda.is_available():
99
 
100
  print("Using device:", device)
101
 
102
- # --- Main Model Initialization ---
103
  MAX_SEED = np.iinfo(np.int32).max
104
  pipe = FluxKontextPipeline.from_pretrained("black-forest-labs/FLUX.1-Kontext-dev", torch_dtype=torch.bfloat16).to("cuda")
105
 
106
- # --- Load All Adapters ---
107
- pipe.load_lora_weights("prithivMLmods/PhotoCleanser-i2i", weight_name="PhotoCleanser-i2i.safetensors", adapter_name="cleanser")
108
- pipe.load_lora_weights("prithivMLmods/Photo-Restore-i2i", weight_name="Photo-Restore-i2i.safetensors", adapter_name="restorer")
109
- pipe.load_lora_weights("prithivMLmods/Polaroid-Warm-i2i", weight_name="Polaroid-Warm-i2i.safetensors", adapter_name="polaroid")
110
- pipe.load_lora_weights("prithivMLmods/Monochrome-Pencil", weight_name="Monochrome-Pencil-i2i.safetensors", adapter_name="pencil")
111
- pipe.load_lora_weights("prithivMLmods/LZO-1-Preview", weight_name="LZO-1-Preview.safetensors", adapter_name="lzo")
112
- pipe.load_lora_weights("prithivMLmods/Kontext-Watermark-Remover", weight_name="Kontext-Watermark-Remover.safetensors", adapter_name="watermark-remover")
113
 
114
- # --- Upscaler Model Initialization ---
115
  aura_sr = AuraSR.from_pretrained("fal/AuraSR-v2")
116
 
117
  @spaces.GPU
@@ -122,18 +118,16 @@ def infer(input_image, prompt, lora_adapter, upscale_image, seed=42, randomize_s
122
  if not input_image:
123
  raise gr.Error("Please upload an image for editing.")
124
 
125
- if lora_adapter == "PhotoCleanser":
126
- pipe.set_adapters(["cleanser"], adapter_weights=[1.0])
127
- elif lora_adapter == "PhotoRestorer":
128
- pipe.set_adapters(["restorer"], adapter_weights=[1.0])
129
- elif lora_adapter == "PolaroidWarm":
130
- pipe.set_adapters(["polaroid"], adapter_weights=[1.0])
131
- elif lora_adapter == "MonochromePencil":
132
- pipe.set_adapters(["pencil"], adapter_weights=[1.0])
133
- elif lora_adapter == "LZO-Zoom":
134
- pipe.set_adapters(["lzo"], adapter_weights=[1.0])
135
- elif lora_adapter == "Kontext-Watermark-Remover":
136
- pipe.set_adapters(["watermark-remover"], adapter_weights=[1.0])
137
 
138
  if randomize_seed:
139
  seed = random.randint(0, MAX_SEED)
@@ -221,12 +215,12 @@ with gr.Blocks(css=css, theme=orange_red_theme) as demo:
221
  with gr.Column():
222
  output_slider = ImageSlider(label="Before / After", show_label=False, interactive=False)
223
  reuse_button = gr.Button("Reuse this image", visible=False)
224
-
225
  with gr.Row():
226
  lora_adapter = gr.Dropdown(
227
  label="Chosen LoRA",
228
- choices=["PhotoCleanser", "PhotoRestorer", "PolaroidWarm", "MonochromePencil", "LZO-Zoom", "Kontext-Watermark-Remover"],
229
- value="PhotoCleanser"
230
  )
231
 
232
  with gr.Row():
@@ -234,14 +228,11 @@ with gr.Blocks(css=css, theme=orange_red_theme) as demo:
234
 
235
  gr.Examples(
236
  examples=[
237
- ["photocleanser/2.png", "[photo content], remove the cat from the image while preserving the background and remaining elements, maintaining realism and original details.", "PhotoCleanser"],
238
- ["photocleanser/1.png", "[photo content], remove the football from the image while preserving the background and remaining elements, maintaining realism and original details.", "PhotoCleanser"],
239
- ["watermark/12.jpeg", "[photo content], remove any watermark text or logos from the image while preserving the background, texture, lighting, and overall realism. Ensure the edited areas blend seamlessly with surrounding details, leaving no visible traces of watermark removal.", "Kontext-Watermark-Remover"],
240
- ["photorestore/1.png", "[photo content], restore and enhance the image by repairing any damage, scratches, or fading. Colorize the photo naturally while preserving authentic textures and details, maintaining a realistic and historically accurate look.", "PhotoRestorer"],
241
- ["lzo/1.jpg", "[photo content], zoom in on the specified [face close-up], enhancing resolution and detail while preserving sharpness, realism, and original context. Maintain natural proportions and background continuity around the zoomed area.", "LZO-Zoom"],
242
- ["photorestore/2.png", "[photo content], restore and enhance the image by repairing any damage, scratches, or fading. Colorize the photo naturally while preserving authentic textures and details, maintaining a realistic and historically accurate look.", "PhotoRestorer"],
243
- ["polaroid/1.png", "[photo content], in the style of a vintage Polaroid, with warm, faded tones, and a white border.", "PolaroidWarm"],
244
- ["pencil/1.png", "[photo content], replicate the image as a pencil illustration, black and white, with sketch-like detailing.", "MonochromePencil"],
245
  ],
246
  inputs=[input_image, prompt, lora_adapter],
247
  outputs=[output_slider, seed],
 
99
 
100
  print("Using device:", device)
101
 
 
102
  MAX_SEED = np.iinfo(np.int32).max
103
  pipe = FluxKontextPipeline.from_pretrained("black-forest-labs/FLUX.1-Kontext-dev", torch_dtype=torch.bfloat16).to("cuda")
104
 
105
+ pipe.load_lora_weights("prithivMLmods/Kontext-Top-Down-View", weight_name="Kontext-Top-Down-View.safetensors", adapter_name="top-down")
106
+ pipe.load_lora_weights("prithivMLmods/Kontext-Bottom-Up-View", weight_name="Kontext-Bottom-Up-View.safetensors", adapter_name="bottom-up")
107
+ pipe.load_lora_weights("prithivMLmods/Kontext-CAM-Left-View", weight_name="Kontext-CAM-Left-View.safetensors", adapter_name="left-view")
108
+ pipe.load_lora_weights("prithivMLmods/Kontext-CAM-Right-View", weight_name="Kontext-CAM-Right-View.safetensors", adapter_name="right-view")
109
+ pipe.load_lora_weights("starsfriday/Kontext-Remover-General-LoRA", weight_name="kontext_remove.safetensors", adapter_name="kontext-remove")
 
 
110
 
 
111
  aura_sr = AuraSR.from_pretrained("fal/AuraSR-v2")
112
 
113
  @spaces.GPU
 
118
  if not input_image:
119
  raise gr.Error("Please upload an image for editing.")
120
 
121
+ if lora_adapter == "Kontext-Top-Down-View":
122
+ pipe.set_adapters(["top-down"], adapter_weights=[1.0])
123
+ elif lora_adapter == "Kontext-Bottom-Up-View":
124
+ pipe.set_adapters(["bottom-up"], adapter_weights=[1.0])
125
+ elif lora_adapter == "Kontext-CAM-Left-View":
126
+ pipe.set_adapters(["left-view"], adapter_weights=[1.0])
127
+ elif lora_adapter == "Kontext-CAM-Right-View":
128
+ pipe.set_adapters(["right-view"], adapter_weights=[1.0])
129
+ elif lora_adapter == "Kontext-Remover":
130
+ pipe.set_adapters(["kontext-remove"], adapter_weights=[1.0])
 
 
131
 
132
  if randomize_seed:
133
  seed = random.randint(0, MAX_SEED)
 
215
  with gr.Column():
216
  output_slider = ImageSlider(label="Before / After", show_label=False, interactive=False)
217
  reuse_button = gr.Button("Reuse this image", visible=False)
218
+
219
  with gr.Row():
220
  lora_adapter = gr.Dropdown(
221
  label="Chosen LoRA",
222
+ choices=["Kontext-Top-Down-View", "Kontext-Remover", "Kontext-Bottom-Up-View", "Kontext-CAM-Left-View", "Kontext-CAM-Right-View"],
223
+ value="Kontext-Top-Down-View"
224
  )
225
 
226
  with gr.Row():
 
228
 
229
  gr.Examples(
230
  examples=[
231
+ ["examples/1.png", "[photo content], recreate the scene from a top-down perspective. Maintain all visual proportions, lighting consistency, and realistic spatial relationships. Ensure the background, textures, and environmental shadows remain naturally aligned from this elevated angle.", "PhotoCleanser"],
232
+ ["examples/2.png", "[photo content], remove the football from the image while preserving the background and remaining elements, maintaining realism and original details.", "PhotoCleanser"],
233
+ ["examples/3.jpeg", "[photo content], remove any watermark text or logos from the image while preserving the background, texture, lighting, and overall realism. Ensure the edited areas blend seamlessly with surrounding details, leaving no visible traces of watermark removal.", "Kontext-Watermark-Remover"],
234
+ ["examples/4.png", "[photo content], restore and enhance the image by repairing any damage, scratches, or fading. Colorize the photo naturally while preserving authentic textures and details, maintaining a realistic and historically accurate look.", "PhotoRestorer"],
235
+ ["examples/5.png", "[photo content], restore and enhance the image by repairing any damage, scratches, or fading. Colorize the photo naturally while preserving authentic textures and details, maintaining a realistic and historically accurate look.", "PhotoRestorer"],
 
 
 
236
  ],
237
  inputs=[input_image, prompt, lora_adapter],
238
  outputs=[output_slider, seed],