Aguilar Elizondo commited on
Commit
5c463fb
·
1 Parent(s): 8013dfb

Connect diffusion pipeline progress to Gradio progress bar

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -56,13 +56,20 @@ def enhance_image_simple(
56
  # Step 1: AI Enhancement
57
  progress(0.3, desc="Applying AI enhancement (this may take several minutes on CPU)...")
58
  try:
 
 
 
 
 
 
59
  enhanced = pipeline_manager.enhance(
60
  image=input_image,
61
  prompt="professional architectural photography, highly detailed, 8k, photorealistic",
62
  negative_prompt="blurry, low quality, distorted, ugly, bad architecture",
63
  strength=strength,
64
  guidance_scale=guidance_scale,
65
- num_inference_steps=30
 
66
  )
67
  except Exception as e:
68
  logger.error(f"AI enhancement failed: {e}", exc_info=True)
@@ -70,7 +77,7 @@ def enhance_image_simple(
70
 
71
  # Step 2: Upscaling
72
  if use_upscaler:
73
- progress(0.7, desc="Upscaling image...")
74
  try:
75
  enhanced = upscale_image(enhanced, scale=2)
76
  except Exception as e:
@@ -78,7 +85,7 @@ def enhance_image_simple(
78
 
79
  # Step 3: Post-processing
80
  if use_postprocess:
81
- progress(0.9, desc="Applying final touches...")
82
  try:
83
  enhanced = postprocess_image(
84
  enhanced,
 
56
  # Step 1: AI Enhancement
57
  progress(0.3, desc="Applying AI enhancement (this may take several minutes on CPU)...")
58
  try:
59
+ # Create a callback to update progress during diffusion
60
+ def update_progress(percent, description):
61
+ # Map internal progress (30-85%) to our progress range
62
+ mapped_progress = 0.3 + (percent / 100) * 0.4 # 30% to 70%
63
+ progress(mapped_progress, desc=description)
64
+
65
  enhanced = pipeline_manager.enhance(
66
  image=input_image,
67
  prompt="professional architectural photography, highly detailed, 8k, photorealistic",
68
  negative_prompt="blurry, low quality, distorted, ugly, bad architecture",
69
  strength=strength,
70
  guidance_scale=guidance_scale,
71
+ num_inference_steps=30,
72
+ progress_callback=update_progress
73
  )
74
  except Exception as e:
75
  logger.error(f"AI enhancement failed: {e}", exc_info=True)
 
77
 
78
  # Step 2: Upscaling
79
  if use_upscaler:
80
+ progress(0.75, desc="Upscaling image...")
81
  try:
82
  enhanced = upscale_image(enhanced, scale=2)
83
  except Exception as e:
 
85
 
86
  # Step 3: Post-processing
87
  if use_postprocess:
88
+ progress(0.85, desc="Applying final touches...")
89
  try:
90
  enhanced = postprocess_image(
91
  enhanced,