Aguilar Elizondo commited on
Commit
4d1f863
·
1 Parent(s): 0ed57c7

Add progress bar and fix postprocess parameters

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -35,24 +35,26 @@ def enhance_image_simple(
35
  strength: float,
36
  guidance_scale: float,
37
  use_upscaler: bool,
38
- use_postprocess: bool
 
39
  ) -> Image.Image:
40
  """Enhance architectural image"""
41
  try:
42
  if input_image is None:
43
  raise ValueError("Please upload an image first")
44
 
45
- logger.info("Starting enhancement process...")
46
 
47
  # Initialize models
48
  try:
 
49
  initialize_models()
50
  except Exception as e:
51
  logger.error(f"Model initialization failed: {e}", exc_info=True)
52
  raise ValueError(f"Failed to load AI models: {str(e)}")
53
 
54
  # Step 1: AI Enhancement
55
- logger.info("Applying AI enhancement...")
56
  try:
57
  enhanced = pipeline_manager.enhance(
58
  image=input_image,
@@ -60,7 +62,7 @@ def enhance_image_simple(
60
  negative_prompt="blurry, low quality, distorted, ugly, bad architecture",
61
  strength=strength,
62
  guidance_scale=guidance_scale,
63
- num_inference_steps=30
64
  )
65
  except Exception as e:
66
  logger.error(f"AI enhancement failed: {e}", exc_info=True)
@@ -68,7 +70,7 @@ def enhance_image_simple(
68
 
69
  # Step 2: Upscaling
70
  if use_upscaler:
71
- logger.info("Upscaling image...")
72
  try:
73
  enhanced = upscale_image(enhanced, scale=2)
74
  except Exception as e:
@@ -76,18 +78,20 @@ def enhance_image_simple(
76
 
77
  # Step 3: Post-processing
78
  if use_postprocess:
79
- logger.info("Post-processing...")
80
  try:
81
  enhanced = postprocess_image(
82
  enhanced,
83
- clahe=True,
84
- sharpen=1.0,
85
- color_enhance=1.1
 
 
86
  )
87
  except Exception as e:
88
  logger.warning(f"Post-processing failed, skipping: {e}")
89
 
90
- logger.info("Enhancement complete!")
91
  return enhanced
92
 
93
  except ValueError as e:
 
35
  strength: float,
36
  guidance_scale: float,
37
  use_upscaler: bool,
38
+ use_postprocess: bool,
39
+ progress=gr.Progress()
40
  ) -> Image.Image:
41
  """Enhance architectural image"""
42
  try:
43
  if input_image is None:
44
  raise ValueError("Please upload an image first")
45
 
46
+ progress(0, desc="Starting enhancement...")
47
 
48
  # Initialize models
49
  try:
50
+ progress(0.1, desc="Initializing AI models...")
51
  initialize_models()
52
  except Exception as e:
53
  logger.error(f"Model initialization failed: {e}", exc_info=True)
54
  raise ValueError(f"Failed to load AI models: {str(e)}")
55
 
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,
 
62
  negative_prompt="blurry, low quality, distorted, ugly, bad architecture",
63
  strength=strength,
64
  guidance_scale=guidance_scale,
65
+ num_inference_steps=20 # Reduced for faster processing
66
  )
67
  except Exception as e:
68
  logger.error(f"AI enhancement failed: {e}", exc_info=True)
 
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
 
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,
85
+ apply_contrast=True,
86
+ apply_sharpening=True,
87
+ apply_color_grading=True,
88
+ apply_grain=False,
89
+ apply_vignette_effect=False
90
  )
91
  except Exception as e:
92
  logger.warning(f"Post-processing failed, skipping: {e}")
93
 
94
+ progress(1.0, desc="Complete!")
95
  return enhanced
96
 
97
  except ValueError as e: