Spaces:
Sleeping
Sleeping
File size: 5,712 Bytes
9451ca9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
import gradio as gr
import os
import warnings
warnings.filterwarnings('ignore')
from src.pipeline import EnhancedAdPipeline
from config.settings import UI_CONFIG
def create_interface():
pipeline = EnhancedAdPipeline()
def process_videos_ui(video1, video2, target_duration, use_ai, gemini_key, progress=gr.Progress()):
if video1 is None:
return None, "β Please upload at least the first video"
try:
if gemini_key and gemini_key.strip():
pipeline.set_gemini_key(gemini_key.strip())
progress(0.1, desc="π Analyzing videos...")
result = pipeline.process_videos(video1, video2, target_duration, use_ai, progress)
if result['success']:
progress(1.0, desc="π Complete!")
status = f"β
Video processing successful!\n"
status += f"π Original duration: {result.get('original_duration', 0):.1f}s\n"
if result.get('second_video'):
status += f"π Second video included\n"
if result.get('ai_generated'):
status += "π€ AI-generated extension added\n"
status += f"π― Final duration: ~{target_duration}s"
return result['output_video'], status
else:
return None, f"β Error: {result.get('error', 'Unknown error')}"
except Exception as e:
return None, f"β Error: {str(e)}"
with gr.Blocks(**UI_CONFIG) as app:
gr.Markdown("""
π¬ Enhanced AI Ad Completion Tool
**Transform your videos into professional commercials using AI!**
β¨ **Features:** Dual video upload β’ AI video generation β’ Gemini-powered prompts β’ Professional processing
""")
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### πΉ Video Inputs")
video1_input = gr.Video(
label="π¬ Primary Video (Required)",
format="mp4"
)
video2_input = gr.Video(
label="π¬ Secondary Video (Optional)",
format="mp4"
)
gr.Markdown("### βοΈ Settings")
duration_slider = gr.Slider(
minimum=10,
maximum=45,
value=20,
step=1,
label="π― Target Duration (seconds)"
)
ai_toggle = gr.Checkbox(
value=True,
label="π€ Use AI Video Generation",
info="Generate new content using AI (requires GPU)"
)
gemini_key_input = gr.Textbox(
label="π Gemini API Key (Optional)",
placeholder="Enter your Gemini API key for better prompts",
type="password"
)
process_btn = gr.Button(
"π Create Enhanced Ad",
variant="primary",
size="lg"
)
gr.Markdown("""
### π How to Use:
1. **Upload primary video** (your main content)
2. **Optional**: Upload second video to combine
3. **Set target duration** for final output
4. **Optional**: Add Gemini API key for better prompts
5. **Enable AI generation** for new content
6. **Click "Create Enhanced Ad"**
**Get Gemini API Key:** [Google AI Studio](https://makersuite.google.com/app/apikey) (Free)
""")
with gr.Column(scale=2):
gr.Markdown("### π Output")
video_output = gr.Video(
label="Enhanced Ad Video",
format="mp4"
)
status_output = gr.Textbox(
label="π Processing Status",
interactive=False,
lines=6
)
gr.Markdown("""
### π¨ What This Tool Does:
**π Video Analysis:**
- Extracts key frames and visual elements
- Transcribes audio content using Whisper
- Analyzes color palette and scene classification
**π€ AI Enhancement:**
- Uses Gemini API for intelligent prompt generation
- Generates new video content with Stable Video Diffusion
- Applies professional color grading and effects
**π¬ Smart Processing:**
- Combines multiple videos with smooth transitions
- Extends to target duration intelligently
- Preserves audio quality throughout
""")
process_btn.click(
fn=process_videos_ui,
inputs=[video1_input, video2_input, duration_slider, ai_toggle, gemini_key_input],
outputs=[video_output, status_output]
)
return app
if __name__ == "__main__":
app = create_interface()
app.launch(server_name="0.0.0.0", server_port=7860, share=True)
|