nniehaus commited on
Commit
d1292c6
·
verified ·
1 Parent(s): 84e2e78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -37
app.py CHANGED
@@ -1,6 +1,5 @@
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")
@@ -12,56 +11,48 @@ openai.api_key = st.secrets["OPENAI_API_KEY"]
12
  def call_openai_api(prompt):
13
  try:
14
  response = openai.ChatCompletion.create(
15
- model="gpt-4", # Ensure you're using a valid model name
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
  # Initialize session state for script to avoid disappearing after download
35
  if 'script' not in st.session_state:
36
  st.session_state.script = ""
37
 
38
  # Streamlit UI for input
39
  business_description = st.text_area(
40
- "Describe your business or video topic/idea:",
41
  placeholder="e.g., We are a local bakery specializing in gluten-free pastries."
42
  )
43
  problem_solved = st.text_input(
44
- "What problem do you solve for your customers?",
45
  placeholder="e.g., Making gluten-free living delicious and easy."
46
  )
47
  services_offered = st.text_input(
48
- "What services do you want to mention in your video?",
49
  placeholder="e.g., Custom gluten-free cakes for special occasions."
50
  )
51
  unique_aspects = st.text_input(
52
- "What makes you unique or separates you from others in your industry?",
53
  placeholder="e.g., Our secret family recipes."
54
  )
55
  name_to_include = st.text_input(
56
- "List any names (your name or business name) you want to include in the video.",
57
  placeholder="e.g., Mary's Gluten-Free Bakery"
58
  )
59
  call_to_action = st.text_input(
60
- "How do you want to be contacted? (Provide one call to action)",
61
  placeholder="e.g., Visit our bakery on Main Street."
62
  )
63
  script_length = st.number_input(
64
- "Desired script length (maximum word count):",
65
  min_value=50, max_value=250, value=150, step=10
66
  )
67
 
@@ -95,33 +86,27 @@ if generate_button:
95
  ]):
96
  st.error("Please fill in all the required fields before generating the script.")
97
  else:
98
- # Creating the prompt as a dictionary
99
- system_prompt = textwrap.dedent(f"""
100
- You are a skilled marketing video script writer for small businesses.
101
- Your task is to create a compelling video script based on user-provided information.
102
- The script should clearly separate numbers and currency values (e.g., "$1,970 per year").
103
- Avoid running words together without spaces or punctuation.
104
- The tone of the script should be {tone.lower()}.
105
- """)
106
-
107
- user_prompt = textwrap.dedent(f"""
108
- Business Description: {business_description}
109
  Problem Solved: {problem_solved}
110
  Services Offered: {services_offered}
111
  Unique Aspects: {unique_aspects}
112
  Names to Include: {name_to_include}
113
  Call to Action: {call_to_action}
114
- Maximum Word Count: {script_length}
115
- """)
116
-
117
- prompt = {
118
- "system": system_prompt,
119
- "user": user_prompt
120
  }
121
 
122
- script = call_openai_api(prompt)
 
123
  if script:
124
- script = clean_script(script) # Clean the output
125
  st.session_state.script = script # Store the generated script in session state
126
 
127
  # Display the script if it exists
 
1
  import streamlit as st
2
  import openai
 
3
 
4
  # Initialize Streamlit app
5
  st.title("Video Script Generator for Small Businesses")
 
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
 
 
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