prithivMLmods commited on
Commit
7fe819b
·
verified ·
1 Parent(s): 72a008b

update app

Browse files
Files changed (1) hide show
  1. app.py +12 -15
app.py CHANGED
@@ -11,7 +11,6 @@ from diffusers import FluxKontextPipeline
11
  from diffusers.utils import load_image
12
  from huggingface_hub import hf_hub_download
13
  from aura_sr import AuraSR
14
- from gradio_imageslider import ImageSlider
15
 
16
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
17
 
@@ -117,7 +116,7 @@ aura_sr = AuraSR.from_pretrained("fal/AuraSR-v2")
117
  @spaces.GPU
118
  def infer(input_image, prompt, lora_adapter, upscale_image, seed=42, randomize_seed=False, guidance_scale=2.5, steps=28, progress=gr.Progress(track_tqdm=True)):
119
  """
120
- Perform image editing and optional upscaling, returning a pair for the ImageSlider.
121
  """
122
  if not input_image:
123
  raise gr.Error("Please upload an image for editing.")
@@ -156,15 +155,15 @@ def infer(input_image, prompt, lora_adapter, upscale_image, seed=42, randomize_s
156
  progress(0.8, desc="Upscaling image...")
157
  image = aura_sr.upscale_4x(image)
158
 
159
- return (original_image, image), seed, gr.Button(visible=True)
160
 
161
  @spaces.GPU
162
  def infer_example(input_image, prompt, lora_adapter):
163
  """
164
- Wrapper function for gr.Examples to call the main infer logic for the slider.
165
  """
166
- (original_image, generated_image), seed, _ = infer(input_image, prompt, lora_adapter, upscale_image=False)
167
- return (original_image, generated_image), seed
168
 
169
  css="""
170
  #col-container {
@@ -174,7 +173,7 @@ css="""
174
  #main-title h1 {font-size: 2.1em !important;}
175
  """
176
 
177
- with gr.Blocks(css=css, theme=steel_blue_theme) as demo:
178
 
179
  with gr.Column(elem_id="col-container"):
180
  gr.Markdown("# **Photo-Mate-i2i**", elem_id="main-title")
@@ -221,7 +220,7 @@ with gr.Blocks(css=css, theme=steel_blue_theme) as demo:
221
  )
222
 
223
  with gr.Column():
224
- output_slider = ImageSlider(label="Before / After", show_label=False, interactive=False)
225
  reuse_button = gr.Button("Reuse this image", visible=False)
226
 
227
  with gr.Row():
@@ -246,11 +245,9 @@ with gr.Blocks(css=css, theme=steel_blue_theme) as demo:
246
  ["unblur/1.jpg", "[photo content], upscale the low-quality image to 4K resolution, enhancing sharpness, clarity, and fine details while preserving the original texture, colors, lighting, and natural appearance. Remove noise, blur, and compression artifacts without over-smoothing or distorting facial or object features. Ensure realistic depth, balanced contrast, and accurate tones, achieving a high-definition, lifelike result that maintains the integrity of the original image.", "Kontext-Unblur-Upscale"],
247
  ["pencil/1.png", "[photo content], replicate the image as a pencil illustration, black and white, with sketch-like detailing.", "MonochromePencil"],
248
  ["unblur/11.jpg", "[photo content], upscale the low-quality image to 4K resolution, enhancing sharpness, clarity, and fine details while preserving the original texture, colors, lighting, and natural appearance. Remove noise, blur, and compression artifacts without over-smoothing or distorting facial or object features. Ensure realistic depth, balanced contrast, and accurate tones, achieving a high-definition, lifelike result that maintains the integrity of the original image.", "Kontext-Unblur-Upscale"],
249
-
250
-
251
  ],
252
  inputs=[input_image, prompt, lora_adapter],
253
- outputs=[output_slider, seed],
254
  fn=infer_example,
255
  cache_examples="lazy",
256
  label="Examples"
@@ -260,13 +257,13 @@ with gr.Blocks(css=css, theme=steel_blue_theme) as demo:
260
  triggers=[run_button.click, prompt.submit],
261
  fn=infer,
262
  inputs=[input_image, prompt, lora_adapter, upscale_checkbox, seed, randomize_seed, guidance_scale, steps],
263
- outputs=[output_slider, seed, reuse_button]
264
  )
265
 
266
  reuse_button.click(
267
- fn=lambda images: images[1] if isinstance(images, (list, tuple)) and len(images) > 1 else images,
268
- inputs=[output_slider],
269
  outputs=[input_image]
270
  )
271
 
272
- demo.launch(mcp_server=True, ssr_mode=False, show_error=True)
 
11
  from diffusers.utils import load_image
12
  from huggingface_hub import hf_hub_download
13
  from aura_sr import AuraSR
 
14
 
15
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
16
 
 
116
  @spaces.GPU
117
  def infer(input_image, prompt, lora_adapter, upscale_image, seed=42, randomize_seed=False, guidance_scale=2.5, steps=28, progress=gr.Progress(track_tqdm=True)):
118
  """
119
+ Perform image editing and optional upscaling, returning the final image.
120
  """
121
  if not input_image:
122
  raise gr.Error("Please upload an image for editing.")
 
155
  progress(0.8, desc="Upscaling image...")
156
  image = aura_sr.upscale_4x(image)
157
 
158
+ return image, seed, gr.Button(visible=True)
159
 
160
  @spaces.GPU
161
  def infer_example(input_image, prompt, lora_adapter):
162
  """
163
+ Wrapper function for gr.Examples.
164
  """
165
+ image, seed, _ = infer(input_image, prompt, lora_adapter, upscale_image=False)
166
+ return image, seed
167
 
168
  css="""
169
  #col-container {
 
173
  #main-title h1 {font-size: 2.1em !important;}
174
  """
175
 
176
+ with gr.Blocks() as demo:
177
 
178
  with gr.Column(elem_id="col-container"):
179
  gr.Markdown("# **Photo-Mate-i2i**", elem_id="main-title")
 
220
  )
221
 
222
  with gr.Column():
223
+ output_image = gr.Image(label="Output Image", interactive=False)
224
  reuse_button = gr.Button("Reuse this image", visible=False)
225
 
226
  with gr.Row():
 
245
  ["unblur/1.jpg", "[photo content], upscale the low-quality image to 4K resolution, enhancing sharpness, clarity, and fine details while preserving the original texture, colors, lighting, and natural appearance. Remove noise, blur, and compression artifacts without over-smoothing or distorting facial or object features. Ensure realistic depth, balanced contrast, and accurate tones, achieving a high-definition, lifelike result that maintains the integrity of the original image.", "Kontext-Unblur-Upscale"],
246
  ["pencil/1.png", "[photo content], replicate the image as a pencil illustration, black and white, with sketch-like detailing.", "MonochromePencil"],
247
  ["unblur/11.jpg", "[photo content], upscale the low-quality image to 4K resolution, enhancing sharpness, clarity, and fine details while preserving the original texture, colors, lighting, and natural appearance. Remove noise, blur, and compression artifacts without over-smoothing or distorting facial or object features. Ensure realistic depth, balanced contrast, and accurate tones, achieving a high-definition, lifelike result that maintains the integrity of the original image.", "Kontext-Unblur-Upscale"],
 
 
248
  ],
249
  inputs=[input_image, prompt, lora_adapter],
250
+ outputs=[output_image, seed],
251
  fn=infer_example,
252
  cache_examples="lazy",
253
  label="Examples"
 
257
  triggers=[run_button.click, prompt.submit],
258
  fn=infer,
259
  inputs=[input_image, prompt, lora_adapter, upscale_checkbox, seed, randomize_seed, guidance_scale, steps],
260
+ outputs=[output_image, seed, reuse_button]
261
  )
262
 
263
  reuse_button.click(
264
+ fn=lambda x: x,
265
+ inputs=[output_image],
266
  outputs=[input_image]
267
  )
268
 
269
+ demo.launch(css=css, theme=steel_blue_theme, mcp_server=True, ssr_mode=False, show_error=True)