Spaces:
Running on Zero
Running on Zero
| import os | |
| import gradio as gr | |
| import config | |
| import prompt_enhancer | |
| import rife_interp | |
| from ui_modules.helpers import load_template | |
| def render_sulphur_vision_suite(input_img): | |
| """ | |
| Silver Feature - Sulphur AI Vision Prompt Engine & Prompt Relay Accordions (open=True). | |
| """ | |
| # 1. Sulphur AI Vision Prompt Engine Accordion (open=True) | |
| with gr.Accordion("🥈 Sulphur AI Vision Prompt Engine (Silver Feature)", open=True): | |
| gr.HTML(load_template("sulphur_silver.html")) | |
| with gr.Row(): | |
| sulphur_subject_input = gr.Textbox( | |
| label="👤 Main Subject / Character", | |
| value="", | |
| lines=2, | |
| placeholder="e.g. beautiful woman in an elegant black dress, portrait detail" | |
| ) | |
| sulphur_adegan_input = gr.Textbox( | |
| label="🎬 Scene Motion / Action Description", | |
| value="", | |
| lines=2, | |
| placeholder="e.g. walking down neon city street, looking back and smiling" | |
| ) | |
| with gr.Row(): | |
| sulphur_camera_dropdown = gr.Dropdown( | |
| choices=["Static", "Close-Up", "Handheld", "POV", "Pan Left-Right", "Zoom In", "Drone View", "Tracking Shot","Tilt Up-Down","Rotation","Zoom Out","Orbit Shot","Steadicam","Slow Motion","Fast Motion","Freeze Frame","Other", "Vertical Shot", "Horizontal Shot", "Diagonal Shot", "Macro Shot", "Telephoto Shot","Random"], | |
| value="Static", | |
| label="🎥 Camera Directing", | |
| scale=1 | |
| ) | |
| sulphur_atmosphere_dropdown = gr.Dropdown( | |
| choices=["Natural Cinematic", "Dim Bedroom", "Neon / Cyberpunk", "Dramatic Night", "Golden Hour Sun", "Studio Portrait","Night Time","Home Theater","Outdoor Night","Indoor Night","Outdoor Day","Indoor Day","Car Night","Car Day","Beach Night","Beach Day","Forest Night","Forest Day","Mountain Night","Mountain Day","Desert Night","Desert Day","Pool Night","Pool Day","Room","Living Room","Kitchen","Bathroom","Garden","Street","Cafe","Restaurant","Bar","Club","Hotel","Mall","Airport","Train","Bus","Subway","Bicycle","Motorcycle","Truck","Boat","Airplane","Spaceship","Other"], | |
| value="Natural Cinematic", | |
| label="💡 Atmosphere & Mood", | |
| scale=1 | |
| ) | |
| sulphur_mode_dropdown = gr.Dropdown( | |
| choices=[ | |
| "🔥 NSFW (Adult / Erotic Uncensored)", | |
| "💖 SFW (Romantic / Sensual Cinematic)", | |
| "🎬 General (Action / Non-Porn Physical)" | |
| ], | |
| value="🔥 NSFW (Adult / Erotic Uncensored)", | |
| label="🔥 Prompt Relay Generation Mode", | |
| scale=1 | |
| ) | |
| with gr.Row(): | |
| sulphur_enable_swap_checkbox = gr.Checkbox( | |
| label="✨ Enable AI Real-ESRGAN / GFPGAN Image Enhancement", | |
| value=False, | |
| info="Super-resolves input image quality via Real-ESRGAN / GFPGAN prior to prompt generation." | |
| ) | |
| sulphur_enhance_btn = gr.Button("⚡ Auto-Generate Uncensored Prompt Relay via Sulphur AI", variant="primary") | |
| sulphur_api_status_box = gr.HTML() | |
| # 2. Multi-Event Timeline Schedule (Prompt Relay) Accordion (open=True) | |
| with gr.Accordion("🎬 Multi-Event Timeline Schedule (Prompt Relay)", open=True): | |
| enable_prompt_relay_checkbox = gr.Checkbox( | |
| label="🎬 Enable Prompt Relay (Multi-Event Timeline Control)", | |
| value=True, | |
| info="⭐ Recommended: Controls multi-event motion per second (Base Prompt is automatically ignored when active)." | |
| ) | |
| relay_prompt_schedule_input = gr.Textbox( | |
| label="🎬 Multi-Event Timeline Schedule (Prompt Relay)", | |
| lines=6, | |
| max_lines=12, | |
| placeholder="[0.0s - 2.0s] A beautiful woman sitting by window\n[2.0s - 4.0s] She stands up and smiles at camera", | |
| value="", | |
| info="Format: [start_sec - end_sec] Detailed event motion description (Base Prompt is not needed)." | |
| ) | |
| return { | |
| "sulphur_subject_input": sulphur_subject_input, | |
| "sulphur_adegan_input": sulphur_adegan_input, | |
| "sulphur_camera_dropdown": sulphur_camera_dropdown, | |
| "sulphur_atmosphere_dropdown": sulphur_atmosphere_dropdown, | |
| "sulphur_mode_dropdown": sulphur_mode_dropdown, | |
| "sulphur_enable_swap_checkbox": sulphur_enable_swap_checkbox, | |
| "sulphur_enhance_btn": sulphur_enhance_btn, | |
| "sulphur_api_status_box": sulphur_api_status_box, | |
| "enable_prompt_relay_checkbox": enable_prompt_relay_checkbox, | |
| "relay_prompt_schedule_input": relay_prompt_schedule_input | |
| } | |
| def render_vip_suite(input_img, output_video): | |
| """ | |
| Gold VIP Suite - Remote GPU RIFE 1080p HD & Advanced Settings Accordions. | |
| Protected by Master VIP Password Key. | |
| """ | |
| with gr.Accordion("💎 Remote VIP GPU RIFE & 1080p HD Video Enhancer", open=True): | |
| with gr.Row(): | |
| vip_master_password_input = gr.Textbox( | |
| label="🔑 Master VIP Password Key", | |
| type="password", | |
| placeholder="Enter Master VIP Key to unlock Remote GPU RIFE & Advanced Settings", | |
| value="", | |
| info="For Master VIP Password, Inbox Me", | |
| scale=3 | |
| ) | |
| validate_vip_key_btn = gr.Button("🔓 Validate VIP Key", variant="primary", scale=1) | |
| vip_auth_status_box = gr.HTML() | |
| with gr.Group(visible=False) as vip_content_group: | |
| gr.HTML(load_template("rife_vip.html")) | |
| vip_standalone_video_input = gr.Video( | |
| label="📹 Input Video to Enhance", | |
| sources=["upload"], | |
| height=200 | |
| ) | |
| with gr.Row(): | |
| vip_send_output_video_btn = gr.Button("📲 Load Generated Output Video to Enhancer", variant="secondary") | |
| enable_vip_rife_checkbox = gr.Checkbox( | |
| label="⚡ Enable VIP Remote RIFE Acceleration (For Main Generator)", | |
| value=False, | |
| info="Auto-offloads main video generation to VIP GPU server." | |
| ) | |
| with gr.Row(): | |
| vip_rife_upscale_checkbox = gr.Checkbox( | |
| label="✨ VIP Real-ESRGAN 1080p HD Video Super-Resolution", | |
| value=True, | |
| info="Upscales 480p/640p video to crystal clear 1080p Full HD using CUDA FP16 TensorRT." | |
| ) | |
| vip_rife_enhance_face_checkbox = gr.Checkbox( | |
| label="👤 VIP Temporal Video Face Sharpening", | |
| value=False, | |
| info="Applies per-frame facial detail restoration via GFPGAN v1.4." | |
| ) | |
| with gr.Row(): | |
| vip_rife_multiplier_radio = gr.Radio( | |
| choices=["2x (32 FPS / 2x Duration)", "4x (64 FPS / 4x Duration)"], | |
| value="2x (32 FPS / 2x Duration)", | |
| label="🚀 VIP RIFE Multiplier", | |
| scale=3 | |
| ) | |
| vip_rife_mode_dropdown = gr.Dropdown( | |
| choices=[ | |
| "High-FPS Motion Smoothness (FPS Boost)", | |
| "Slow-Motion / Extend Duration (Multiplied Seconds)" | |
| ], | |
| value="High-FPS Motion Smoothness (FPS Boost)", | |
| label="⚙️ VIP RIFE Output Mode", | |
| scale=3 | |
| ) | |
| vip_standalone_enhance_btn = gr.Button("💎 Run VIP Remote GPU RIFE & 1080p HD Upscaler", variant="primary") | |
| vip_standalone_video_output = gr.Video(label="📹 Enhanced 1080p HD VIP Video Result", interactive=False) | |
| with gr.Accordion("⚙️ Advanced Settings", open=False): | |
| custom_filename_input = gr.Textbox( | |
| label="Output Filename (Optional)", | |
| placeholder="e.g.: my_generated_video_01", | |
| value="", | |
| info="Saved as .mp4 format automatically." | |
| ) | |
| negative_prompt_input = gr.Textbox(label="Negative Prompt", value=config.default_negative_prompt, lines=3, max_lines=6) | |
| with gr.Row(): | |
| quality_slider = gr.Slider(minimum=1, maximum=10, step=1, value=6, label="Video Quality Grade") | |
| steps_slider = gr.Slider(minimum=1, maximum=30, step=1, value=4, label="Inference Steps") | |
| with gr.Row(): | |
| seed_input = gr.Slider(label="Seed", minimum=0, maximum=config.MAX_SEED, step=1, value=42, interactive=True) | |
| randomize_seed_checkbox = gr.Checkbox(label="🎲 Randomize seed", value=True, interactive=True) | |
| with gr.Row(): | |
| guidance_scale_input = gr.Slider(minimum=0.0, maximum=10.0, step=0.5, value=1, label="Guidance Scale") | |
| guidance_scale_2_input = gr.Slider(minimum=0.0, maximum=10.0, step=0.5, value=1, label="Guidance Scale 2") | |
| with gr.Row(): | |
| scheduler_dropdown = gr.Dropdown( | |
| label="Scheduler", | |
| choices=list(config.SCHEDULER_MAP.keys()), | |
| value="UniPCMultistep" | |
| ) | |
| flow_shift_slider = gr.Slider(minimum=0.5, maximum=15.0, step=0.1, value=3.0, label="Flow Shift") | |
| def validate_master_vip_key(user_key): | |
| vip_secret = (config.VIP_PASS or os.environ.get("VIP_PASSWORD", "")).strip() | |
| user_key_str = (user_key or "").strip() | |
| if vip_secret and user_key_str != vip_secret: | |
| status_html = """ | |
| <div style="background: rgba(239, 68, 68, 0.15); border: 1px solid #ef4444; border-radius: 10px; padding: 10px 14px; color: #f87171; font-weight: 700; margin-top: 6px;"> | |
| ❌ <b>Invalid VIP Password Key!</b> Access Denied. | |
| </div> | |
| """ | |
| return gr.update(visible=False), status_html | |
| status_html = """ | |
| <div style="background: rgba(16, 185, 129, 0.15); border: 1px solid #10b981; border-radius: 10px; padding: 10px 14px; color: #34d399; font-weight: 700; margin-top: 6px;"> | |
| ✅ <b>VIP Key Authorized Successfully!</b> All Remote GPU & Advanced Settings Unlocked. | |
| </div> | |
| """ | |
| return gr.update(visible=True), status_html | |
| validate_vip_key_btn.click( | |
| fn=validate_master_vip_key, | |
| inputs=[vip_master_password_input], | |
| outputs=[vip_content_group, vip_auth_status_box] | |
| ) | |
| vip_send_output_video_btn.click( | |
| fn=lambda v: v, | |
| inputs=[output_video], | |
| outputs=[vip_standalone_video_input] | |
| ) | |
| def run_standalone_vip_rife_enhance(video_path, multiplier, slow_motion, upscale, enhance_face, password): | |
| if not video_path or not os.path.exists(video_path): | |
| raise gr.Error("Please upload or load a video file to enhance first.") | |
| vip_secret = (config.VIP_PASS or os.environ.get("VIP_PASSWORD", "")).strip() | |
| if vip_secret and (password or "").strip() != vip_secret: | |
| raise gr.Error("❌ Invalid VIP Password Access Key!") | |
| mult_val = 2 | |
| if "4x" in str(multiplier): | |
| mult_val = 4 | |
| elif "8x" in str(multiplier): | |
| mult_val = 8 | |
| is_slow_mo = ("Slow-Motion" in str(slow_motion)) or ("Duration" in str(slow_motion)) | |
| res = rife_interp.call_sulphur_rife_api( | |
| video_path=video_path, | |
| multiplier=mult_val, | |
| slow_motion=is_slow_mo, | |
| upscale=upscale, | |
| enhance_face=enhance_face | |
| ) | |
| if not res or not os.path.exists(res): | |
| raise gr.Error("Sulphur AI VIP Remote RIFE GPU Server is offline or returned an error.") | |
| return res | |
| vip_standalone_enhance_btn.click( | |
| fn=run_standalone_vip_rife_enhance, | |
| inputs=[ | |
| vip_standalone_video_input, | |
| vip_rife_multiplier_radio, | |
| vip_rife_mode_dropdown, | |
| vip_rife_upscale_checkbox, | |
| vip_rife_enhance_face_checkbox, | |
| vip_master_password_input | |
| ], | |
| outputs=[vip_standalone_video_output] | |
| ) | |
| return { | |
| "vip_master_password_input": vip_master_password_input, | |
| "validate_vip_key_btn": validate_vip_key_btn, | |
| "vip_auth_status_box": vip_auth_status_box, | |
| "enable_vip_rife_checkbox": enable_vip_rife_checkbox, | |
| "vip_rife_multiplier_radio": vip_rife_multiplier_radio, | |
| "vip_rife_mode_dropdown": vip_rife_mode_dropdown, | |
| "vip_rife_upscale_checkbox": vip_rife_upscale_checkbox, | |
| "vip_rife_enhance_face_checkbox": vip_rife_enhance_face_checkbox, | |
| "vip_standalone_video_input": vip_standalone_video_input, | |
| "vip_send_output_video_btn": vip_send_output_video_btn, | |
| "vip_standalone_enhance_btn": vip_standalone_enhance_btn, | |
| "vip_standalone_video_output": vip_standalone_video_output, | |
| "custom_filename_input": custom_filename_input, | |
| "negative_prompt_input": negative_prompt_input, | |
| "quality_slider": quality_slider, | |
| "steps_slider": steps_slider, | |
| "seed_input": seed_input, | |
| "randomize_seed_checkbox": randomize_seed_checkbox, | |
| "guidance_scale_input": guidance_scale_input, | |
| "guidance_scale_2_input": guidance_scale_2_input, | |
| "scheduler_dropdown": scheduler_dropdown, | |
| "flow_shift_slider": flow_shift_slider | |
| } | |