import streamlit as st import openai import os # Page configuration st.set_page_config( page_title="AI Video Script Generator", page_icon="🎬", layout="wide", initial_sidebar_state="collapsed" ) # Custom CSS for better styling st.markdown(""" """, unsafe_allow_html=True) # Initialize OpenAI API key openai.api_key = os.getenv("OPENAI_API_KEY") # Function to generate script with OpenAI API def generate_video_script(prompt_data): if not openai.api_key: st.error("Please set your OPENAI_API_KEY environment variable") return None try: system_message = f""" You are an expert video marketing scriptwriter specializing in promotional content for businesses. You create compelling scripts that: - Hook viewers in the first 3 seconds - Tell a clear story about the business value - Build emotional connection with the audience - End with a powerful call-to-action - Use {prompt_data['tone'].lower()} tone throughout Your scripts contain ONLY the words to be spoken - no directions, no scene descriptions, just the exact dialogue for a promotional video. """ user_message = f""" Create a promotional video script with these details: Business: {prompt_data['business']} Problem Solved: {prompt_data['problem']} Services: {prompt_data['services']} Unique Value: {prompt_data['unique']} Business Name: {prompt_data['name']} Call to Action: {prompt_data['cta']} Script Length: Maximum {prompt_data['length']} words Video Type: {prompt_data['video_type']} Target Audience: {prompt_data['audience']} Make it {prompt_data['tone'].lower()} and ensure it's compelling from start to finish. """ response = openai.ChatCompletion.create( model="gpt-4", messages=[ {"role": "system", "content": system_message}, {"role": "user", "content": user_message} ], temperature=0.8 ) return response["choices"][0]["message"]["content"] except Exception as e: st.error(f"Error generating script: {str(e)}") return None # Initialize session state if 'generated_script' not in st.session_state: st.session_state.generated_script = "" if 'show_form' not in st.session_state: st.session_state.show_form = True # Header st.markdown('

🎬 AI Video Script Generator

', unsafe_allow_html=True) st.markdown('

Create compelling promotional videos that convert viewers into customers

', unsafe_allow_html=True) # Benefits section st.markdown("""

📈 Why Video Marketing Works

• 87% of businesses use video as a marketing tool
• Videos increase engagement by 1200% compared to text
• 64% of customers make a purchase after watching a video
• Get professional scripts in under 60 seconds!

""", unsafe_allow_html=True) if st.session_state.show_form: # Input form in columns for better layout col1, col2 = st.columns([2, 1]) with col1: st.markdown('

📝 Tell Us About Your Business

', unsafe_allow_html=True) # Basic business info business_description = st.text_area( "What does your business do?", placeholder="e.g., We're a local coffee shop that roasts our own beans and creates custom blends for coffee lovers.", height=80, help="Describe your business in simple terms that anyone can understand" ) problem_solved = st.text_input( "What problem do you solve for customers?", placeholder="e.g., We help busy professionals get amazing coffee without the wait", help="Focus on the main pain point you address" ) services_offered = st.text_input( "What specific services/products should we highlight?", placeholder="e.g., Custom coffee subscriptions, corporate catering, barista training", help="List 2-3 key offerings you want to promote" ) unique_aspects = st.text_input( "What makes you different from competitors?", placeholder="e.g., Only coffee shop in town with beans roasted daily on-site", help="Your unique selling proposition" ) name_to_include = st.text_input( "Business name to include in the script:", placeholder="e.g., Downtown Coffee Co.", help="How you want your business referenced" ) call_to_action = st.text_input( "How should viewers contact you?", placeholder="e.g., Visit us at 123 Main Street or order online at our website", help="One clear action you want viewers to take" ) with col2: st.markdown('

🎯 Customize Your Script

', unsafe_allow_html=True) video_type = st.selectbox( "Video Type:", [ "Social Media Ad (Instagram/TikTok)", "YouTube Promotional Video", "Website Homepage Video", "Facebook/LinkedIn Ad", "Product Showcase", "Customer Testimonial Style", "Behind-the-Scenes", "Educational/How-To" ], help="Choose the platform or style you're targeting" ) target_audience = st.selectbox( "Target Audience:", [ "Local Community", "Young Professionals (25-35)", "Small Business Owners", "Families with Children", "Seniors (55+)", "Students", "Health-Conscious Consumers", "Luxury Market", "Budget-Conscious Shoppers", "General Audience" ], help="Who are you trying to reach?" ) tone_options = [ "Professional & Trustworthy", "Friendly & Conversational", "Exciting & Energetic", "Warm & Personal", "Confident & Bold", "Humorous & Fun", "Inspiring & Motivational", "Urgent & Persuasive", "Calm & Reassuring", "Expert & Educational" ] tone = st.selectbox("Script Tone:", tone_options, help="How do you want to sound?") script_length = st.slider( "Script Length (words):", min_value=50, max_value=300, value=150, step=25, help="Shorter = social media, Longer = detailed explanations" ) # Length guide st.markdown("""
📏 Length Guide:
• 50-100 words: Quick social media ad
• 100-200 words: Standard promotional video
• 200-300 words: Detailed explanation video
""", unsafe_allow_html=True) # Generate button st.markdown("
", unsafe_allow_html=True) col1, col2, col3 = st.columns([1, 2, 1]) with col2: if st.button("🚀 Generate My Video Script", use_container_width=True): # Validation required_fields = [ business_description, problem_solved, services_offered, unique_aspects, name_to_include, call_to_action ] if not all(required_fields): st.error("⚠️ Please fill in all required fields to generate your script.") else: with st.spinner("🎬 Crafting your perfect video script..."): prompt_data = { 'business': business_description, 'problem': problem_solved, 'services': services_offered, 'unique': unique_aspects, 'name': name_to_include, 'cta': call_to_action, 'length': script_length, 'tone': tone, 'video_type': video_type, 'audience': target_audience } script = generate_video_script(prompt_data) if script: st.session_state.generated_script = script st.session_state.show_form = False st.rerun() # Display generated script if st.session_state.generated_script and not st.session_state.show_form: st.markdown('

🎬 Your Video Script is Ready!

', unsafe_allow_html=True) # Script display formatted_script = st.session_state.generated_script.replace('\n', '
') st.markdown(f"""

📜 Your Promotional Video Script

{formatted_script}
""", unsafe_allow_html=True) # Action buttons col1, col2, col3 = st.columns([1, 1, 1]) with col1: st.download_button( label="📥 Download Script", data=st.session_state.generated_script, file_name=f"video_script_{name_to_include.replace(' ', '_').lower()}.txt", mime="text/plain", use_container_width=True ) with col2: if st.button("✏️ Edit Details", use_container_width=True): st.session_state.show_form = True st.rerun() with col3: if st.button("🔄 Generate New Script", use_container_width=True): st.session_state.generated_script = "" st.session_state.show_form = True st.rerun() # Tips section st.markdown("""

🎯 Tips for Recording Your Video:

• Practice reading the script 2-3 times before recording
• Speak clearly and at a moderate pace
• Maintain eye contact with the camera
• Use good lighting (face the light source)
• Keep background simple and professional
• Record multiple takes and choose the best one
""", unsafe_allow_html=True) # Footer st.markdown("

", unsafe_allow_html=True) st.markdown("""

🎬 Ready to create videos that convert? Generate unlimited scripts and grow your business!

""", unsafe_allow_html=True)