| """ |
| Simple Comic Generator App |
| - NO comic styling (preserves colors) |
| - ONLY 12 meaningful story panels |
| - Clean grid layout |
| """ |
|
|
| import os |
| import time |
| from flask import Flask, request, render_template, send_from_directory |
| from backend.subtitles.subs_real import get_real_subtitles |
| from backend.simple_comic_generator import SimpleComicGenerator |
| from backend.advanced_image_enhancer import AdvancedImageEnhancer |
|
|
| app = Flask(__name__) |
|
|
| |
| os.makedirs('video', exist_ok=True) |
| os.makedirs('frames/final', exist_ok=True) |
| os.makedirs('output', exist_ok=True) |
|
|
| class CleanComicGenerator: |
| def __init__(self): |
| self.video_path = 'video/uploaded.mp4' |
| self.simple_generator = SimpleComicGenerator() |
| self.enhancer = AdvancedImageEnhancer() |
| |
| def generate(self): |
| """Generate clean comic with meaningful panels only""" |
| start_time = time.time() |
| |
| try: |
| print("π¬ Starting Clean Comic Generation...") |
| print("π Settings:") |
| print(" - Target: 12 meaningful panels") |
| print(" - No comic styling (preserve colors)") |
| print(" - Grid layout: 3x4") |
| |
| |
| print("\nπ Extracting subtitles...") |
| get_real_subtitles(self.video_path) |
| |
| |
| print("\nπ Selecting meaningful story moments...") |
| success = self.simple_generator.generate_meaningful_comic(self.video_path) |
| |
| if success: |
| |
| print("\n⨠Enhancing image quality...") |
| self._enhance_frames() |
| |
| print(f"\nβ
Comic generated in {time.time() - start_time:.1f} seconds!") |
| print("π View at: output/comic_simple.html") |
| return True |
| else: |
| print("β Comic generation failed") |
| return False |
| |
| except Exception as e: |
| print(f"β Error: {e}") |
| return False |
| |
| def _enhance_frames(self): |
| """Enhance frames with color preservation""" |
| frames_dir = 'frames/final' |
| frames = [f for f in os.listdir(frames_dir) if f.endswith('.png')] |
| |
| |
| self.enhancer.use_ai_models = False |
| |
| for i, frame in enumerate(frames): |
| try: |
| frame_path = os.path.join(frames_dir, frame) |
| print(f" Enhancing {frame} ({i+1}/{len(frames)})...") |
| |
| |
| import cv2 |
| img = cv2.imread(frame_path) |
| |
| |
| kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]]) / 1 |
| sharpened = cv2.filter2D(img, -1, kernel) |
| |
| |
| enhanced = cv2.addWeighted(img, 0.7, sharpened, 0.3, 0) |
| |
| |
| cv2.imwrite(frame_path, enhanced, [cv2.IMWRITE_PNG_COMPRESSION, 0]) |
| |
| except Exception as e: |
| print(f" β οΈ Enhancement failed for {frame}: {e}") |
|
|
| |
| comic_generator = CleanComicGenerator() |
|
|
| @app.route('/') |
| def index(): |
| return render_template('index.html') |
|
|
| @app.route('/uploader', methods=['GET', 'POST']) |
| def upload_file(): |
| if request.method == 'POST': |
| try: |
| if 'file' not in request.files: |
| return "β No file uploaded" |
| |
| f = request.files['file'] |
| if f.filename == '': |
| return "β No file selected" |
| |
| |
| f.save("video/uploaded.mp4") |
| print(f"β
Video saved: {f.filename}") |
| |
| |
| success = comic_generator.generate() |
| |
| if success: |
| return ''' |
| <html> |
| <body style="font-family: Arial; padding: 20px;"> |
| <h2>β
Comic Generated Successfully!</h2> |
| <p>Created 12 meaningful story panels with preserved colors.</p> |
| <a href="/comic" style="display: inline-block; padding: 10px 20px; background: #4CAF50; color: white; text-decoration: none; border-radius: 5px;">View Comic</a> |
| </body> |
| </html> |
| ''' |
| else: |
| return "β Comic generation failed" |
| |
| except Exception as e: |
| return f"β Error: {str(e)}" |
|
|
| @app.route('/comic') |
| def view_comic(): |
| """Serve the generated comic""" |
| return send_from_directory('output', 'comic_simple.html') |
|
|
| @app.route('/frames/final/<path:filename>') |
| def serve_frame(filename): |
| """Serve frame images""" |
| return send_from_directory('frames/final', filename) |
|
|
| if __name__ == '__main__': |
| import numpy as np |
| |
| print("π Starting Simple Comic Generator...") |
| print("β¨ Features:") |
| print(" - 12 meaningful story panels") |
| print(" - Original colors preserved") |
| print(" - Clean grid layout") |
| print(" - No unnecessary processing") |
| print("\nπ Open browser to: http://localhost:5000") |
| |
| app.run(debug=True, host='0.0.0.0', port=5000) |