nniehaus's picture
Create app.py
8d3cc4d verified
Raw History Blame
12.6 kB
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("""
<style>
.main-header {
text-align: center;
color: #1f4e79;
font-size: 3rem;
font-weight: bold;
margin-bottom: 0.5rem;
}
.sub-header {
text-align: center;
color: #666;
font-size: 1.2rem;
margin-bottom: 2rem;
}
.section-header {
color: #1f4e79;
font-size: 1.5rem;
font-weight: bold;
margin-top: 2rem;
margin-bottom: 1rem;
border-bottom: 2px solid #e0e0e0;
padding-bottom: 0.5rem;
}
.highlight-box {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 2rem;
border-radius: 15px;
color: white;
margin: 2rem 0;
}
.feature-box {
background: #f8f9fa;
padding: 1.5rem;
border-radius: 10px;
border-left: 4px solid #667eea;
margin: 1rem 0;
}
.script-output {
background: #ffffff;
padding: 2rem;
border-radius: 15px;
border: 2px solid #e0e0e0;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin: 2rem 0;
}
.stButton > button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 0.75rem 2rem;
border-radius: 25px;
font-weight: bold;
font-size: 1.1rem;
transition: all 0.3s ease;
}
.stButton > button:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
</style>
""", 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('<h1 class="main-header">🎬 AI Video Script Generator</h1>', unsafe_allow_html=True)
st.markdown('<p class="sub-header">Create compelling promotional videos that convert viewers into customers</p>', unsafe_allow_html=True)
# Benefits section
st.markdown("""
<div class="highlight-box">
<h3>πŸ“ˆ Why Video Marketing Works</h3>
<p>β€’ 87% of businesses use video as a marketing tool<br>
β€’ Videos increase engagement by 1200% compared to text<br>
β€’ 64% of customers make a purchase after watching a video<br>
β€’ Get professional scripts in under 60 seconds!</p>
</div>
""", 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('<h2 class="section-header">πŸ“ Tell Us About Your Business</h2>', 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('<h2 class="section-header">🎯 Customize Your Script</h2>', 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("""
<div class="feature-box">
<strong>πŸ“ Length Guide:</strong><br>
β€’ 50-100 words: Quick social media ad<br>
β€’ 100-200 words: Standard promotional video<br>
β€’ 200-300 words: Detailed explanation video
</div>
""", unsafe_allow_html=True)
# Generate button
st.markdown("<br>", 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('<h2 class="section-header">🎬 Your Video Script is Ready!</h2>', unsafe_allow_html=True)
# Script display
formatted_script = st.session_state.generated_script.replace('\n', '<br>')
st.markdown(f"""
<div class="script-output">
<h3 style="color: #1f4e79; margin-bottom: 1rem;">πŸ“œ Your Promotional Video Script</h3>
<div style="font-size: 1.1rem; line-height: 1.6; color: #333;">
{formatted_script}
</div>
</div>
""", 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("""
<div class="feature-box">
<h4>🎯 Tips for Recording Your Video:</h4>
β€’ Practice reading the script 2-3 times before recording<br>
β€’ Speak clearly and at a moderate pace<br>
β€’ Maintain eye contact with the camera<br>
β€’ Use good lighting (face the light source)<br>
β€’ Keep background simple and professional<br>
β€’ Record multiple takes and choose the best one
</div>
""", unsafe_allow_html=True)
# Footer
st.markdown("<br><br>", unsafe_allow_html=True)
st.markdown("""
<div style="text-align: center; color: #666; padding: 2rem;">
<p>🎬 Ready to create videos that convert? Generate unlimited scripts and grow your business!</p>
</div>
""", unsafe_allow_html=True)