Spaces:
Sleeping
Sleeping
Update app.py
Browse files2 unmodified lines34566786 unmodified lines151617191819203 unmodified lines24252629272831322930313632333435361 unmodified line383940444142435 unmodified lines49505156575859606152535455565758596061626364656667686970717273747576777868798070818283848576777879868788899091869293899495962 unmodified linesimport gradio as grimport whisper
# Load the highly optimized whisper frameworktry: model = whisper.load_model("tiny")except Exception as e:6 unmodified lines print("[SYSTEM] Executing AI Speech Audio Transcription Matrix...") result = model.transcribe(audio_input, word_timestamps=True) # Calculate exact duration boundary limits duration = 10.0 if result.get("segments"): duration = result["segments"][-1]["end"]3 unmodified lines final_output = "viral_captions_pip.mp4" # ---------------------------------------------------- # PHASE 1: GENERATE ADVANCED SUB-STATION ALPHA VECTOR SCRIPT # GENERATE ADVANCED SUB-STATION ALPHA VECTOR SCRIPT # ---------------------------------------------------- # This defines the exact MrBeast / Alex Hormozi high-impact style attributes: # FontName=Arial, FontSize=36, PrimaryColor=White, OutlineColor=Black, BorderThickness=4, ShadowDistance=2 with open(ass_filename, "w", encoding="utf-8") as f: f.write("[Script Info]\nScriptType: v4.00+\nPlayResX: 720\nPlayResY: 1280\n\n") f.write("[V4+ Styles]\nFormat: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\n") f.write("Style: Hormozi,Arial,38,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100,100,2,0,1,4,2,5,10,10,10,1\n\n") # Thick 4px black borders, Arial Black font for that signature high-end layout style f.write("Style: Hormozi,Arial Black,42,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100,100,2,0,1,4,1,5,10,10,10,1\n\n") f.write("[Events]\nFormat: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n") for segment in result.get("segments", []):1 unmodified line start_time = word["start"] end_time = word["end"] # Format time objects to standard timestamp tracking format (H:MM:SS.CC) def format_ass_time(secs): h = int(secs // 3600) m = int((secs % 3600) // 60)5 unmodified lines raw_text = word["word"].strip().upper() # Apply Dynamic Contextual Highlights (Hormozi Yellow Matrix) if raw_text in ["YOU", "NOW", "START", "NEED", "STOP", "VIRAL", "MONEY", "GET", "MAKING"]: formatted_text = f"{{\\1c&H0000FFFF\\fscx115\\fscy115}}{raw_text}{{\\r}}" # Apply Secondary Highlight (MrBeast Neon Green Matrix) elif raw_text in ["BEST", "PERFECT", "HIGH", "FAST", "POWERFUL", "SMART"]: formatted_text = f"{{\\1c&H0000FF00\\fscx115\\fscy115}}{raw_text}{{\\r}}" # Setup Advanced Word Color Matching Playbooks # Note: ASS Color format uses &H00BBGGRR (Blue Blue, Green Green, Red Red) # π‘ YELLOW preset words yellow_words = ["YOU", "NOW", "START", "NEED", "LOOK", "LISTEN", "THIS", "WAIT", "WATCH"] # π’ GREEN preset words green_words = ["MONEY", "CASH", "WIN", "BEST", "PERFECT", "FAST", "POWERFUL", "SMART", "MAKE", "MAKING"] # π΄ RED preset words red_words = ["STOP", "FREEZE", "WRONG", "BAD", "CUT", "FAIL", "NO", "DON'T", "NEVER", "CLOSE"] # π PINK preset words pink_words = ["VIRAL", "INSANE", "SHOCKING", "SECRET", "WHAT", "CRAZY", "WOW", "AMAZING", "BROKE"]
if raw_text in yellow_words: formatted_text = f"{{\\1c&H0000FFFF\\fscx112\\fscy112}}{raw_text}{{\\r}}" elif raw_text in green_words: formatted_text = f"{{\\1c&H0000FF00\\fscx112\\fscy112}}{raw_text}{{\\r}}" elif raw_text in red_words: formatted_text = f"{{\\1c&H000000FF\\fscx112\\fscy112}}{raw_text}{{\\r}}" elif raw_text in pink_words: formatted_text = f"{{\\1c&H00CC00FF\\fscx112\\fscy112}}{raw_text}{{\\r}}" else: # Standard elegant white for normal fill text words formatted_text = f"{{\\fscx100\\fscy100}}{raw_text}{{\\r}}" f.write(f"Dialogue: 0,{t_start},{t_end},Hormozi,,0,0,0,,{formatted_text}\n")
# ---------------------------------------------------- # PHASE 2: GENERATE SOLID ULTRA-HD GREEN SCREEN MATRIX # HARDWARE FUSION GRAPHICS CHANNELS # ---------------------------------------------------- print("[SYSTEM] Compiling hardware color plane canvas...") subprocess.run([ 'ffmpeg', '-y', '-f', 'lavfi', '-i', f'color=c=0x00ff00:s=720x1280:d={duration}:r=30', '-c:v', 'libx264', '-pix_fmt', 'yuv420p', video_raw ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
# ---------------------------------------------------- # PHASE 3: FUSE VECTOR TRACKS AND AUDIO IN ONE PASS # ---------------------------------------------------- print("[SYSTEM] Executing Dual-Stream Hardware Subtitle Fusion...") subprocess.run([ 'ffmpeg', '-y', '-i', video_raw, '-i', audio_input, '-vf', f'ass={ass_filename}', '-c:v', 'libx264', '-c:a', 'aac', '-map', '0:v:0', '-map', '1:a:0', '-shortest', final_output ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) print("[SYSTEM] Process complete. Clean file architecture outputted successfully.") return final_output
# Initialize high-performance web endpointdemo = gr.Interface( fn=generate_viral_caption_pipeline, inputs=gr.Audio(type="filepath", label="Input Audio Node File"), app.py+25-21