Aguilar Elizondo commited on
Commit
0897497
·
1 Parent(s): f79b01f

Add detailed error handling and user-friendly error messages

Browse files
Files changed (1) hide show
  1. app.py +37 -17
app.py CHANGED
@@ -39,43 +39,63 @@ def enhance_image_simple(
39
  ) -> Image.Image:
40
  """Enhance architectural image"""
41
  try:
 
 
 
42
  logger.info("Starting enhancement process...")
43
 
44
  # Initialize models
45
- initialize_models()
 
 
 
 
46
 
47
  # Step 1: AI Enhancement
48
  logger.info("Applying AI enhancement...")
49
- enhanced = enhance_with_diffusion(
50
- pipeline_manager,
51
- input_image,
52
- prompt="professional architectural photography, highly detailed, 8k, photorealistic",
53
- strength=strength,
54
- guidance_scale=guidance_scale,
55
- num_inference_steps=30
56
- )
 
 
 
 
57
 
58
  # Step 2: Upscaling
59
  if use_upscaler:
60
  logger.info("Upscaling image...")
61
- enhanced = upscale_image(enhanced, scale=2)
 
 
 
62
 
63
  # Step 3: Post-processing
64
  if use_postprocess:
65
  logger.info("Post-processing...")
66
- enhanced = postprocess_image(
67
- enhanced,
68
- clahe=True,
69
- sharpen=1.0,
70
- color_enhance=1.1
71
- )
 
 
 
72
 
73
  logger.info("Enhancement complete!")
74
  return enhanced
75
 
 
 
 
76
  except Exception as e:
77
  logger.error(f"Enhancement failed: {e}", exc_info=True)
78
- raise
79
 
80
  # Create simple interface
81
  iface = gr.Interface(
 
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 = enhance_with_diffusion(
58
+ pipeline_manager,
59
+ input_image,
60
+ prompt="professional architectural photography, highly detailed, 8k, photorealistic",
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)
67
+ raise ValueError(f"AI enhancement failed: {str(e)}")
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:
75
+ logger.warning(f"Upscaling failed, skipping: {e}")
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:
94
+ # Re-raise ValueError with user-friendly message
95
+ raise gr.Error(str(e))
96
  except Exception as e:
97
  logger.error(f"Enhancement failed: {e}", exc_info=True)
98
+ raise gr.Error(f"Enhancement failed: {str(e)}")
99
 
100
  # Create simple interface
101
  iface = gr.Interface(