nniehaus commited on
Commit
bd97fba
Β·
verified Β·
1 Parent(s): d738a43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +347 -107
app.py CHANGED
@@ -1,123 +1,363 @@
1
  import streamlit as st
2
- import openai
 
3
 
4
- # Initialize Streamlit app
5
- st.title("Video Script Generator for Small Businesses")
 
 
 
 
 
6
 
7
- # Accessing the OpenAI API key securely
8
- openai.api_key = st.secrets["OPENAI_API_KEY"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- # Function to call OpenAI API
11
- def call_openai_api(prompt):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  try:
13
- response = openai.ChatCompletion.create(
14
- model="gpt-4", # Ensure you're using a valid model
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  messages=[
16
- {"role": "system", "content": prompt['system']},
17
- {"role": "user", "content": prompt['user']}
18
- ]
 
19
  )
20
- return response.choices[0].message['content']
 
 
21
  except Exception as e:
22
- st.error(f"An error occurred: {str(e)}")
23
  return None
24
 
25
- # Initialize session state for script to avoid disappearing after download
26
- if 'script' not in st.session_state:
27
- st.session_state.script = ""
 
 
28
 
29
- # Streamlit UI for input
30
- business_description = st.text_area(
31
- "Describe your business or video topic/idea:",
32
- placeholder="e.g., We are a local bakery specializing in gluten-free pastries."
33
- )
34
- problem_solved = st.text_input(
35
- "What problem do you solve for your customers?",
36
- placeholder="e.g., Making gluten-free living delicious and easy."
37
- )
38
- services_offered = st.text_input(
39
- "What services do you want to mention in your video?",
40
- placeholder="e.g., Custom gluten-free cakes for special occasions."
41
- )
42
- unique_aspects = st.text_input(
43
- "What makes you unique or separates you from others in your industry?",
44
- placeholder="e.g., Our secret family recipes."
45
- )
46
- name_to_include = st.text_input(
47
- "List any names (your name or business name) you want to include in the video.",
48
- placeholder="e.g., Mary's Gluten-Free Bakery"
49
- )
50
- call_to_action = st.text_input(
51
- "How do you want to be contacted? (Provide one call to action)",
52
- placeholder="e.g., Visit our bakery on Main Street."
53
- )
54
- script_length = st.number_input(
55
- "Desired script length (maximum word count):",
56
- min_value=50, max_value=250, value=150, step=10
57
- )
58
-
59
- # Add tone selection with at least 10 options
60
- tone_options = [
61
- "Professional",
62
- "Casual",
63
- "Humorous",
64
- "Inspirational",
65
- "Persuasive",
66
- "Friendly",
67
- "Urgent",
68
- "Confident",
69
- "Empathetic",
70
- "Excited"
71
- ]
72
- tone = st.selectbox("Choose the tone for your video script:", options=tone_options)
73
 
74
- generate_button = st.button('Generate Video Script')
 
 
 
 
 
 
 
 
 
75
 
76
- # Handling button click
77
- if generate_button:
78
- # Ensure required fields are not empty
79
- if not all([
80
- business_description,
81
- problem_solved,
82
- services_offered,
83
- unique_aspects,
84
- name_to_include,
85
- call_to_action
86
- ]):
87
- st.error("Please fill in all the required fields before generating the script.")
88
- else:
89
- # Creating the prompt as a dictionary (reintegrating original high-performing details)
90
- user_prompt = {
91
- "system": f"""
92
- Act as a small business marketing video script writer. You respond with fully written video scripts that contain only the words that should be read out
93
- loud into the camera. The scripts you create do not include shot directions, references to who is speaking, or any other extraneous notes that are not the actual
94
- words that should be read out loud. As a small business video marketing expert, you have studied the most effective marketing and social media videos made by small
95
- businesses. The video scripts are short, always coming in under the specified maximum word count. They always begin with engaging opening lines that tease what the
96
- rest of the video is about and they end with a single strong call to action. The tone of the script should be {tone.lower()}.""",
97
- "user": f"""
98
- Industry: {business_description}
99
- Problem Solved: {problem_solved}
100
- Services Offered: {services_offered}
101
- Unique Aspects: {unique_aspects}
102
- Names to Include: {name_to_include}
103
- Call to Action: {call_to_action}
104
- Script Length: {script_length} words maximum."""
105
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
- # Calling the API
108
- script = call_openai_api(user_prompt)
109
- if script:
110
- st.session_state.script = script # Store the generated script in session state
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
- # Display the script if it exists
113
- if st.session_state.script:
114
- st.markdown("### Generated Video Script")
115
- st.write(st.session_state.script)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
- # Add a download button
118
- st.download_button(
119
- label="πŸ“₯ Download Script as Text File",
120
- data=st.session_state.script,
121
- file_name='video_script.txt',
122
- mime='text/plain'
123
- )
 
1
  import streamlit as st
2
+ from openai import OpenAI
3
+ import os
4
 
5
+ # Page configuration
6
+ st.set_page_config(
7
+ page_title="AI Video Script Generator",
8
+ page_icon="🎬",
9
+ layout="wide",
10
+ initial_sidebar_state="collapsed"
11
+ )
12
 
13
+ # Custom CSS for better styling
14
+ st.markdown("""
15
+ <style>
16
+ .main-header {
17
+ text-align: center;
18
+ color: #1f4e79;
19
+ font-size: 3rem;
20
+ font-weight: bold;
21
+ margin-bottom: 0.5rem;
22
+ }
23
+ .sub-header {
24
+ text-align: center;
25
+ color: #666;
26
+ font-size: 1.2rem;
27
+ margin-bottom: 2rem;
28
+ }
29
+ .section-header {
30
+ color: #1f4e79;
31
+ font-size: 1.5rem;
32
+ font-weight: bold;
33
+ margin-top: 2rem;
34
+ margin-bottom: 1rem;
35
+ border-bottom: 2px solid #e0e0e0;
36
+ padding-bottom: 0.5rem;
37
+ }
38
+ .highlight-box {
39
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
40
+ padding: 2rem;
41
+ border-radius: 15px;
42
+ color: white;
43
+ margin: 2rem 0;
44
+ }
45
+ .feature-box {
46
+ background: #f8f9fa;
47
+ padding: 1.5rem;
48
+ border-radius: 10px;
49
+ border-left: 4px solid #667eea;
50
+ margin: 1rem 0;
51
+ }
52
+ .script-output {
53
+ background: #ffffff;
54
+ padding: 2rem;
55
+ border-radius: 15px;
56
+ border: 2px solid #e0e0e0;
57
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
58
+ margin: 2rem 0;
59
+ }
60
+ .stButton > button {
61
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
62
+ color: white;
63
+ border: none;
64
+ padding: 0.75rem 2rem;
65
+ border-radius: 25px;
66
+ font-weight: bold;
67
+ font-size: 1.1rem;
68
+ transition: all 0.3s ease;
69
+ }
70
+ .stButton > button:hover {
71
+ transform: translateY(-2px);
72
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
73
+ }
74
+ </style>
75
+ """, unsafe_allow_html=True)
76
 
77
+ # Initialize OpenAI client
78
+ @st.cache_resource
79
+ def get_openai_client():
80
+ try:
81
+ return OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
82
+ except Exception as e:
83
+ st.error("Please set your OPENAI_API_KEY environment variable")
84
+ return None
85
+
86
+ client = get_openai_client()
87
+
88
+ # Function to generate script with current OpenAI API
89
+ def generate_video_script(prompt_data):
90
+ if not client:
91
+ return None
92
+
93
  try:
94
+ system_message = f"""
95
+ You are an expert video marketing scriptwriter specializing in promotional content for businesses.
96
+ You create compelling scripts that:
97
+ - Hook viewers in the first 3 seconds
98
+ - Tell a clear story about the business value
99
+ - Build emotional connection with the audience
100
+ - End with a powerful call-to-action
101
+ - Use {prompt_data['tone'].lower()} tone throughout
102
+
103
+ Your scripts contain ONLY the words to be spoken - no directions, no scene descriptions,
104
+ just the exact dialogue for a promotional video.
105
+ """
106
+
107
+ user_message = f"""
108
+ Create a promotional video script with these details:
109
+
110
+ Business: {prompt_data['business']}
111
+ Problem Solved: {prompt_data['problem']}
112
+ Services: {prompt_data['services']}
113
+ Unique Value: {prompt_data['unique']}
114
+ Business Name: {prompt_data['name']}
115
+ Call to Action: {prompt_data['cta']}
116
+ Script Length: Maximum {prompt_data['length']} words
117
+ Video Type: {prompt_data['video_type']}
118
+ Target Audience: {prompt_data['audience']}
119
+
120
+ Make it {prompt_data['tone'].lower()} and ensure it's compelling from start to finish.
121
+ """
122
+
123
+ response = client.chat.completions.create(
124
+ model="gpt-4",
125
  messages=[
126
+ {"role": "system", "content": system_message},
127
+ {"role": "user", "content": user_message}
128
+ ],
129
+ temperature=0.8
130
  )
131
+
132
+ return response.choices[0].message.content
133
+
134
  except Exception as e:
135
+ st.error(f"Error generating script: {str(e)}")
136
  return None
137
 
138
+ # Initialize session state
139
+ if 'generated_script' not in st.session_state:
140
+ st.session_state.generated_script = ""
141
+ if 'show_form' not in st.session_state:
142
+ st.session_state.show_form = True
143
 
144
+ # Header
145
+ st.markdown('<h1 class="main-header">🎬 AI Video Script Generator</h1>', unsafe_allow_html=True)
146
+ st.markdown('<p class="sub-header">Create compelling promotional videos that convert viewers into customers</p>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
+ # Benefits section
149
+ st.markdown("""
150
+ <div class="highlight-box">
151
+ <h3>πŸ“ˆ Why Video Marketing Works</h3>
152
+ <p>β€’ 87% of businesses use video as a marketing tool<br>
153
+ β€’ Videos increase engagement by 1200% compared to text<br>
154
+ β€’ 64% of customers make a purchase after watching a video<br>
155
+ β€’ Get professional scripts in under 60 seconds!</p>
156
+ </div>
157
+ """, unsafe_allow_html=True)
158
 
159
+ if st.session_state.show_form:
160
+ # Input form in columns for better layout
161
+ col1, col2 = st.columns([2, 1])
162
+
163
+ with col1:
164
+ st.markdown('<h2 class="section-header">πŸ“ Tell Us About Your Business</h2>', unsafe_allow_html=True)
165
+
166
+ # Basic business info
167
+ business_description = st.text_area(
168
+ "What does your business do?",
169
+ placeholder="e.g., We're a local coffee shop that roasts our own beans and creates custom blends for coffee lovers.",
170
+ height=80,
171
+ help="Describe your business in simple terms that anyone can understand"
172
+ )
173
+
174
+ problem_solved = st.text_input(
175
+ "What problem do you solve for customers?",
176
+ placeholder="e.g., We help busy professionals get amazing coffee without the wait",
177
+ help="Focus on the main pain point you address"
178
+ )
179
+
180
+ services_offered = st.text_input(
181
+ "What specific services/products should we highlight?",
182
+ placeholder="e.g., Custom coffee subscriptions, corporate catering, barista training",
183
+ help="List 2-3 key offerings you want to promote"
184
+ )
185
+
186
+ unique_aspects = st.text_input(
187
+ "What makes you different from competitors?",
188
+ placeholder="e.g., Only coffee shop in town with beans roasted daily on-site",
189
+ help="Your unique selling proposition"
190
+ )
191
+
192
+ name_to_include = st.text_input(
193
+ "Business name to include in the script:",
194
+ placeholder="e.g., Downtown Coffee Co.",
195
+ help="How you want your business referenced"
196
+ )
197
+
198
+ call_to_action = st.text_input(
199
+ "How should viewers contact you?",
200
+ placeholder="e.g., Visit us at 123 Main Street or order online at our website",
201
+ help="One clear action you want viewers to take"
202
+ )
203
+
204
+ with col2:
205
+ st.markdown('<h2 class="section-header">🎯 Customize Your Script</h2>', unsafe_allow_html=True)
206
+
207
+ video_type = st.selectbox(
208
+ "Video Type:",
209
+ [
210
+ "Social Media Ad (Instagram/TikTok)",
211
+ "YouTube Promotional Video",
212
+ "Website Homepage Video",
213
+ "Facebook/LinkedIn Ad",
214
+ "Product Showcase",
215
+ "Customer Testimonial Style",
216
+ "Behind-the-Scenes",
217
+ "Educational/How-To"
218
+ ],
219
+ help="Choose the platform or style you're targeting"
220
+ )
221
+
222
+ target_audience = st.selectbox(
223
+ "Target Audience:",
224
+ [
225
+ "Local Community",
226
+ "Young Professionals (25-35)",
227
+ "Small Business Owners",
228
+ "Families with Children",
229
+ "Seniors (55+)",
230
+ "Students",
231
+ "Health-Conscious Consumers",
232
+ "Luxury Market",
233
+ "Budget-Conscious Shoppers",
234
+ "General Audience"
235
+ ],
236
+ help="Who are you trying to reach?"
237
+ )
238
+
239
+ tone_options = [
240
+ "Professional & Trustworthy",
241
+ "Friendly & Conversational",
242
+ "Exciting & Energetic",
243
+ "Warm & Personal",
244
+ "Confident & Bold",
245
+ "Humorous & Fun",
246
+ "Inspiring & Motivational",
247
+ "Urgent & Persuasive",
248
+ "Calm & Reassuring",
249
+ "Expert & Educational"
250
+ ]
251
+
252
+ tone = st.selectbox("Script Tone:", tone_options, help="How do you want to sound?")
253
+
254
+ script_length = st.slider(
255
+ "Script Length (words):",
256
+ min_value=50,
257
+ max_value=300,
258
+ value=150,
259
+ step=25,
260
+ help="Shorter = social media, Longer = detailed explanations"
261
+ )
262
+
263
+ # Length guide
264
+ st.markdown("""
265
+ <div class="feature-box">
266
+ <strong>πŸ“ Length Guide:</strong><br>
267
+ β€’ 50-100 words: Quick social media ad<br>
268
+ β€’ 100-200 words: Standard promotional video<br>
269
+ β€’ 200-300 words: Detailed explanation video
270
+ </div>
271
+ """, unsafe_allow_html=True)
272
 
273
+ # Generate button
274
+ st.markdown("<br>", unsafe_allow_html=True)
275
+ col1, col2, col3 = st.columns([1, 2, 1])
276
+ with col2:
277
+ if st.button("πŸš€ Generate My Video Script", use_container_width=True):
278
+ # Validation
279
+ required_fields = [
280
+ business_description, problem_solved, services_offered,
281
+ unique_aspects, name_to_include, call_to_action
282
+ ]
283
+
284
+ if not all(required_fields):
285
+ st.error("⚠️ Please fill in all required fields to generate your script.")
286
+ else:
287
+ with st.spinner("🎬 Crafting your perfect video script..."):
288
+ prompt_data = {
289
+ 'business': business_description,
290
+ 'problem': problem_solved,
291
+ 'services': services_offered,
292
+ 'unique': unique_aspects,
293
+ 'name': name_to_include,
294
+ 'cta': call_to_action,
295
+ 'length': script_length,
296
+ 'tone': tone,
297
+ 'video_type': video_type,
298
+ 'audience': target_audience
299
+ }
300
+
301
+ script = generate_video_script(prompt_data)
302
+ if script:
303
+ st.session_state.generated_script = script
304
+ st.session_state.show_form = False
305
+ st.rerun()
306
 
307
+ # Display generated script
308
+ if st.session_state.generated_script and not st.session_state.show_form:
309
+ st.markdown('<h2 class="section-header">🎬 Your Video Script is Ready!</h2>', unsafe_allow_html=True)
310
+
311
+ # Script display
312
+ st.markdown(f"""
313
+ <div class="script-output">
314
+ <h3 style="color: #1f4e79; margin-bottom: 1rem;">πŸ“œ Your Promotional Video Script</h3>
315
+ <div style="font-size: 1.1rem; line-height: 1.6; color: #333;">
316
+ {st.session_state.generated_script.replace('\n', '<br>')}
317
+ </div>
318
+ </div>
319
+ """, unsafe_allow_html=True)
320
+
321
+ # Action buttons
322
+ col1, col2, col3 = st.columns([1, 1, 1])
323
+
324
+ with col1:
325
+ st.download_button(
326
+ label="πŸ“₯ Download Script",
327
+ data=st.session_state.generated_script,
328
+ file_name=f"video_script_{name_to_include.replace(' ', '_').lower()}.txt",
329
+ mime="text/plain",
330
+ use_container_width=True
331
+ )
332
+
333
+ with col2:
334
+ if st.button("✏️ Edit Details", use_container_width=True):
335
+ st.session_state.show_form = True
336
+ st.rerun()
337
+
338
+ with col3:
339
+ if st.button("πŸ”„ Generate New Script", use_container_width=True):
340
+ st.session_state.generated_script = ""
341
+ st.session_state.show_form = True
342
+ st.rerun()
343
+
344
+ # Tips section
345
+ st.markdown("""
346
+ <div class="feature-box">
347
+ <h4>🎯 Tips for Recording Your Video:</h4>
348
+ β€’ Practice reading the script 2-3 times before recording<br>
349
+ β€’ Speak clearly and at a moderate pace<br>
350
+ β€’ Maintain eye contact with the camera<br>
351
+ β€’ Use good lighting (face the light source)<br>
352
+ β€’ Keep background simple and professional<br>
353
+ β€’ Record multiple takes and choose the best one
354
+ </div>
355
+ """, unsafe_allow_html=True)
356
 
357
+ # Footer
358
+ st.markdown("<br><br>", unsafe_allow_html=True)
359
+ st.markdown("""
360
+ <div style="text-align: center; color: #666; padding: 2rem;">
361
+ <p>🎬 Ready to create videos that convert? Generate unlimited scripts and grow your business!</p>
362
+ </div>
363
+ """, unsafe_allow_html=True)