Spaces:
tester343
/
Configuration error

jhh6576 commited on
Commit
3178424
Β·
verified Β·
1 Parent(s): 63f6f13

Update app_enhanced.py

Browse files
Files changed (1) hide show
  1. app_enhanced.py +17 -16
app_enhanced.py CHANGED
@@ -13,7 +13,20 @@ import shutil
13
  from typing import List
14
  import traceback
15
 
16
- # Import enhanced modules
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  try:
18
  from backend.ai_enhanced_core import (
19
  image_processor, comic_styler, face_detector, layout_optimizer
@@ -21,8 +34,6 @@ try:
21
  from backend.ai_bubble_placement import ai_bubble_placer
22
  from backend.subtitles.subs_real import get_real_subtitles
23
  from backend.keyframes.keyframes_simple import generate_keyframes_simple
24
- # --- FIX: Import the module itself to prevent namespace issues ---
25
- from backend.keyframes import keyframes
26
  from backend.class_def import bubble, panel, Page
27
  from backend.simple_color_enhancer import SimpleColorEnhancer
28
  from backend.quality_color_enhancer import QualityColorEnhancer
@@ -58,7 +69,6 @@ except Exception as e:
58
  STORY_EXTRACTOR_AVAILABLE = False
59
  print(f"⚠️ Smart story extractor not available: {e}")
60
 
61
- # --- FIX: Use __name__ for Flask app initialization ---
62
  app = Flask(__name__)
63
 
64
  # Import editor routes
@@ -76,7 +86,6 @@ os.makedirs('output', exist_ok=True)
76
 
77
  class EnhancedComicGenerator:
78
  """High-quality comic generation with AI enhancement"""
79
- # --- FIX: Corrected constructor name from 'init' to '__init__' ---
80
  def __init__(self):
81
  self.video_path = 'video/uploaded.mp4'
82
  self.frames_dir = 'frames/final'
@@ -299,8 +308,8 @@ class EnhancedComicGenerator:
299
  return False
300
 
301
  print("βœ‚οΈ Cropping black bars...")
302
- # --- FIX: Call the function from its imported module 'keyframes' ---
303
- black_x, black_y, _, _ = keyframes.black_bar_crop()
304
  print("βœ… Black bars cropped.")
305
 
306
  print("🎨 Enhancing images...")
@@ -850,8 +859,6 @@ def upload_file():
850
  f.save(comic_generator.video_path)
851
  success = comic_generator.generate_comic()
852
  if success:
853
- # In a containerized environment like HF Spaces, webbrowser.open won't work.
854
- # The user will access the app via the public URL provided by the Space.
855
  return "πŸŽ‰ Enhanced Comic Created Successfully! Please refresh your browser and go to the /comic endpoint."
856
  else:
857
  return "❌ Comic generation failed"
@@ -913,24 +920,18 @@ def regenerate_frame_route():
913
  def view_comic():
914
  return send_from_directory('output', 'page.html')
915
 
916
- # --- FIX: Corrected Flask route syntax for dynamic paths ---
917
  @app.route('/output/<path:filename>')
918
  def output_file(filename):
919
  return send_from_directory('output', filename)
920
 
921
- # --- FIX: Corrected Flask route syntax for dynamic paths ---
922
  @app.route('/frames/final/<path:filename>')
923
  def frame_file(filename):
924
  return send_from_directory('frames/final', filename)
925
 
926
- # --- FIX: Use __name__ == '__main__' for the execution block ---
927
  if __name__ == '__main__':
928
- # --- CHANGE: Use the port assigned by Hugging Face Spaces or default to 5000 ---
929
- # This makes the app compatible with HF Spaces and also allows local execution.
930
- port = int(os.getenv("PORT", 7860))
931
 
932
  print("πŸš€ Starting Enhanced Comic Generator...")
933
  print(f"🌐 Web interface starting on host 0.0.0.0, port {port}")
934
- # In Hugging Face Spaces, you will access the app through the public URL provided, not localhost.
935
 
936
  app.run(debug=False, host='0.0.0.0', port=port)
 
13
  from typing import List
14
  import traceback
15
 
16
+ # --- FIX: Isolate the problematic import and provide a fallback ---
17
+ # This makes the app run even if the module is missing, skipping the feature.
18
+ try:
19
+ from backend.keyframes.keyframes import black_bar_crop
20
+ print("βœ… Black bar cropping module loaded.")
21
+ except Exception as e:
22
+ print(f"⚠️ Could not load black_bar_crop from backend.keyframes.keyframes: {e}")
23
+ print("⚠️ Black bar cropping will be SKIPPED. A default value of (0,0) will be used.")
24
+ # Define a dummy function so the rest of the program doesn't crash
25
+ def black_bar_crop():
26
+ # Return default coordinates (x=0, y=0) and dimensions
27
+ return 0, 0, None, None
28
+
29
+ # Import other enhanced modules
30
  try:
31
  from backend.ai_enhanced_core import (
32
  image_processor, comic_styler, face_detector, layout_optimizer
 
34
  from backend.ai_bubble_placement import ai_bubble_placer
35
  from backend.subtitles.subs_real import get_real_subtitles
36
  from backend.keyframes.keyframes_simple import generate_keyframes_simple
 
 
37
  from backend.class_def import bubble, panel, Page
38
  from backend.simple_color_enhancer import SimpleColorEnhancer
39
  from backend.quality_color_enhancer import QualityColorEnhancer
 
69
  STORY_EXTRACTOR_AVAILABLE = False
70
  print(f"⚠️ Smart story extractor not available: {e}")
71
 
 
72
  app = Flask(__name__)
73
 
74
  # Import editor routes
 
86
 
87
  class EnhancedComicGenerator:
88
  """High-quality comic generation with AI enhancement"""
 
89
  def __init__(self):
90
  self.video_path = 'video/uploaded.mp4'
91
  self.frames_dir = 'frames/final'
 
308
  return False
309
 
310
  print("βœ‚οΈ Cropping black bars...")
311
+ # --- FIX: This call now uses either the real function or the dummy one ---
312
+ black_x, black_y, _, _ = black_bar_crop()
313
  print("βœ… Black bars cropped.")
314
 
315
  print("🎨 Enhancing images...")
 
859
  f.save(comic_generator.video_path)
860
  success = comic_generator.generate_comic()
861
  if success:
 
 
862
  return "πŸŽ‰ Enhanced Comic Created Successfully! Please refresh your browser and go to the /comic endpoint."
863
  else:
864
  return "❌ Comic generation failed"
 
920
  def view_comic():
921
  return send_from_directory('output', 'page.html')
922
 
 
923
  @app.route('/output/<path:filename>')
924
  def output_file(filename):
925
  return send_from_directory('output', filename)
926
 
 
927
  @app.route('/frames/final/<path:filename>')
928
  def frame_file(filename):
929
  return send_from_directory('frames/final', filename)
930
 
 
931
  if __name__ == '__main__':
932
+ port = int(os.getenv("PORT", 5000))
 
 
933
 
934
  print("πŸš€ Starting Enhanced Comic Generator...")
935
  print(f"🌐 Web interface starting on host 0.0.0.0, port {port}")
 
936
 
937
  app.run(debug=False, host='0.0.0.0', port=port)