Spaces:
Sleeping
Sleeping
Update app.py
Browse files2 unmodified lines34567896 unmodified lines161718192021223 unmodified lines26272829303132333435363738391 unmodified line414243444546475 unmodified lines535455565758596061626364656667686970717273747576777879808182838485868788899091922 unmodified linesimport gradio as grimport whisper# Load the highly optimized whisper frameworktry:model = whisper.load_model("tiny")except Exception as e:6 unmodified linesprint("[SYSTEM] Executing AI Speech Audio Transcription Matrix...")result = model.transcribe(audio_input, word_timestamps=True)# Calculate exact duration boundary limitsduration = 10.0if result.get("segments"):duration = result["segments"][-1]["end"]3 unmodified linesfinal_output = "viral_captions_pip.mp4"# ----------------------------------------------------# PHASE 1: 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=2with 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")f.write("[Events]\nFormat: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n")for segment in result.get("segments", []):1 unmodified linestart_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 linesraw_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}}"else: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# ----------------------------------------------------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"),2 unmodified lines3456786 unmodified lines1516171819203 unmodified lines242526272829303132333435361 unmodified line3839404142435 unmodified lines4950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495962 unmodified linesimport gradio as grimport whispertry:model = whisper.load_model("tiny")except Exception as e:6 unmodified linesprint("[SYSTEM] Executing AI Speech Audio Transcription Matrix...")result = model.transcribe(audio_input, word_timestamps=True)duration = 10.0if result.get("segments"):duration = result["segments"][-1]["end"]3 unmodified linesfinal_output = "viral_captions_pip.mp4"# ----------------------------------------------------# GENERATE ADVANCED SUB-STATION ALPHA VECTOR SCRIPT# ----------------------------------------------------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")# Thick 4px black borders, Arial Black font for that signature high-end layout stylef.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 linestart_time = word["start"]end_time = word["end"]def format_ass_time(secs):h = int(secs // 3600)m = int((secs % 3600) // 60)5 unmodified linesraw_text = word["word"].strip().upper()# Setup Advanced Word Color Matching Playbooks# Note: ASS Color format uses &H00BBGGRR (Blue Blue, Green Green, Red Red)# π‘ YELLOW preset wordsyellow_words = ["YOU", "NOW", "START", "NEED", "LOOK", "LISTEN", "THIS", "WAIT", "WATCH"]# π’ GREEN preset wordsgreen_words = ["MONEY", "CASH", "WIN", "BEST", "PERFECT", "FAST", "POWERFUL", "SMART", "MAKE", "MAKING"]# π΄ RED preset wordsred_words = ["STOP", "FREEZE", "WRONG", "BAD", "CUT", "FAIL", "NO", "DON'T", "NEVER", "CLOSE"]# π PINK preset wordspink_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 wordsformatted_text = f"{{\\fscx100\\fscy100}}{raw_text}{{\\r}}"f.write(f"Dialogue: 0,{t_start},{t_end},Hormozi,,0,0,0,,{formatted_text}\n")# ----------------------------------------------------# HARDWARE FUSION GRAPHICS CHANNELS# ----------------------------------------------------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)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)return final_outputdemo = gr.Interface(fn=generate_viral_caption_pipeline,inputs=gr.Audio(type="filepath", label="Input Audio Node File"),
app.py+25-21