nniehaus commited on
Commit
267080d
·
verified ·
1 Parent(s): dfc0d11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -13
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  import openai
 
3
 
4
  # Initialize Streamlit app
5
  st.title("Video Script Generator for Small Businesses")
@@ -15,13 +16,21 @@ def call_openai_api(prompt):
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
  # Streamlit UI for input
26
  business_description = st.text_area(
27
  "Describe your business or video topic/idea:",
@@ -41,7 +50,7 @@ unique_aspects = st.text_input(
41
  )
42
  name_to_include = st.text_input(
43
  "List any names (your name or business name) you want to include in the video.",
44
- placeholder="e.g., 123 Custom Blinds or Mary Smith"
45
  )
46
  call_to_action = st.text_input(
47
  "How do you want to be contacted? (Provide one call to action)",
@@ -83,24 +92,32 @@ if generate_button:
83
  st.error("Please fill in all the required fields before generating the script.")
84
  else:
85
  # Creating the prompt as a dictionary
86
- user_prompt = {
87
- "system": f"""
88
- 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
89
- 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
90
- 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
91
- 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
92
- 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()}.""",
93
- "user": f"""
94
- Industry: {business_description}
 
95
  Problem Solved: {problem_solved}
96
  Services Offered: {services_offered}
97
  Unique Aspects: {unique_aspects}
98
  Names to Include: {name_to_include}
99
  Call to Action: {call_to_action}
100
- Script Length: {script_length} words maximum."""
 
 
 
 
 
101
  }
102
- script = call_openai_api(user_prompt)
 
103
  if script:
 
104
  st.markdown("### Generated Video Script")
105
  st.write(script)
106
 
 
1
  import streamlit as st
2
  import openai
3
+ import textwrap
4
 
5
  # Initialize Streamlit app
6
  st.title("Video Script Generator for Small Businesses")
 
16
  messages=[
17
  {"role": "system", "content": prompt['system']},
18
  {"role": "user", "content": prompt['user']}
19
+ ],
20
+ temperature=0.5 # Lowered to produce more structured output
21
  )
22
  return response.choices[0].message['content']
23
  except Exception as e:
24
  st.error(f"An error occurred: {str(e)}")
25
  return None
26
 
27
+ # Post-processing to clean up concatenated words or numbers
28
+ def clean_script(script):
29
+ import re
30
+ cleaned_script = re.sub(r"(\d+)([a-zA-Z])", r"\1 \2", script)
31
+ cleaned_script = re.sub(r"([a-zA-Z])(\d+)", r"\1 \2", cleaned_script)
32
+ return cleaned_script
33
+
34
  # Streamlit UI for input
35
  business_description = st.text_area(
36
  "Describe your business or video topic/idea:",
 
50
  )
51
  name_to_include = st.text_input(
52
  "List any names (your name or business name) you want to include in the video.",
53
+ placeholder="e.g., Mary's Gluten-Free Bakery"
54
  )
55
  call_to_action = st.text_input(
56
  "How do you want to be contacted? (Provide one call to action)",
 
92
  st.error("Please fill in all the required fields before generating the script.")
93
  else:
94
  # Creating the prompt as a dictionary
95
+ system_prompt = textwrap.dedent(f"""
96
+ You are a skilled marketing video script writer for small businesses.
97
+ Your task is to create a compelling video script based on user-provided information.
98
+ The script should clearly separate numbers and currency values (e.g., "$1,970 per year").
99
+ Avoid running words together without spaces or punctuation.
100
+ The tone of the script should be {tone.lower()}.
101
+ """)
102
+
103
+ user_prompt = textwrap.dedent(f"""
104
+ Business Description: {business_description}
105
  Problem Solved: {problem_solved}
106
  Services Offered: {services_offered}
107
  Unique Aspects: {unique_aspects}
108
  Names to Include: {name_to_include}
109
  Call to Action: {call_to_action}
110
+ Maximum Word Count: {script_length}
111
+ """)
112
+
113
+ prompt = {
114
+ "system": system_prompt,
115
+ "user": user_prompt
116
  }
117
+
118
+ script = call_openai_api(prompt)
119
  if script:
120
+ script = clean_script(script) # Clean the output
121
  st.markdown("### Generated Video Script")
122
  st.write(script)
123