Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import openai
|
| 3 |
|
| 4 |
-
#
|
| 5 |
st.title("Video Script Generator for Small Businesses")
|
| 6 |
|
| 7 |
# Accessing the OpenAI API key securely
|
|
@@ -11,12 +11,9 @@ openai.api_key = st.secrets["OPENAI_API_KEY"]
|
|
| 11 |
def call_openai_api(prompt):
|
| 12 |
try:
|
| 13 |
response = openai.ChatCompletion.create(
|
| 14 |
-
model="gpt-
|
| 15 |
messages=[
|
| 16 |
-
{
|
| 17 |
-
"role": "system",
|
| 18 |
-
"content": prompt['system']
|
| 19 |
-
},
|
| 20 |
{"role": "user", "content": prompt['user']}
|
| 21 |
]
|
| 22 |
)
|
|
@@ -26,38 +23,93 @@ def call_openai_api(prompt):
|
|
| 26 |
return None
|
| 27 |
|
| 28 |
# Streamlit UI for input
|
| 29 |
-
business_description = st.text_area(
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
generate_button = st.button('Generate Video Script')
|
| 38 |
|
| 39 |
# Handling button click
|
| 40 |
if generate_button:
|
| 41 |
-
#
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
Problem Solved: {problem_solved}
|
| 52 |
-
Services Offered: {services_offered}
|
| 53 |
-
Unique Aspects: {unique_aspects}
|
| 54 |
-
Names to Include: {name_to_include}
|
| 55 |
-
Call to Action: {call_to_action}
|
| 56 |
-
Script Length: {script_length} words maximum."""
|
| 57 |
-
}
|
| 58 |
-
script = call_openai_api(user_prompt)
|
| 59 |
-
if script:
|
| 60 |
-
st.markdown("### Generated Video Script")
|
| 61 |
-
st.write(script)
|
| 62 |
else:
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
| 11 |
def call_openai_api(prompt):
|
| 12 |
try:
|
| 13 |
response = openai.ChatCompletion.create(
|
| 14 |
+
model="gpt-4", # Ensure you're using a valid model name
|
| 15 |
messages=[
|
| 16 |
+
{"role": "system", "content": prompt['system']},
|
|
|
|
|
|
|
|
|
|
| 17 |
{"role": "user", "content": prompt['user']}
|
| 18 |
]
|
| 19 |
)
|
|
|
|
| 23 |
return None
|
| 24 |
|
| 25 |
# Streamlit UI for input
|
| 26 |
+
business_description = st.text_area(
|
| 27 |
+
"Describe your business or video topic/idea:",
|
| 28 |
+
placeholder="e.g., We are a local bakery specializing in gluten-free pastries."
|
| 29 |
+
)
|
| 30 |
+
problem_solved = st.text_input(
|
| 31 |
+
"What problem do you solve for your customers?",
|
| 32 |
+
placeholder="e.g., Making gluten-free living delicious and easy."
|
| 33 |
+
)
|
| 34 |
+
services_offered = st.text_input(
|
| 35 |
+
"What services do you want to mention in your video?",
|
| 36 |
+
placeholder="e.g., Custom gluten-free cakes for special occasions."
|
| 37 |
+
)
|
| 38 |
+
unique_aspects = st.text_input(
|
| 39 |
+
"What makes you unique or separates you from others in your industry?",
|
| 40 |
+
placeholder="e.g., Our secret family recipes."
|
| 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)",
|
| 48 |
+
placeholder="e.g., Visit our bakery on Main Street."
|
| 49 |
+
)
|
| 50 |
+
script_length = st.number_input(
|
| 51 |
+
"Desired script length (maximum word count):",
|
| 52 |
+
min_value=50, max_value=250, value=150, step=10
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Add tone selection with at least 10 options
|
| 56 |
+
tone_options = [
|
| 57 |
+
"Professional",
|
| 58 |
+
"Casual",
|
| 59 |
+
"Humorous",
|
| 60 |
+
"Inspirational",
|
| 61 |
+
"Persuasive",
|
| 62 |
+
"Friendly",
|
| 63 |
+
"Urgent",
|
| 64 |
+
"Confident",
|
| 65 |
+
"Empathetic",
|
| 66 |
+
"Excited"
|
| 67 |
+
]
|
| 68 |
+
tone = st.selectbox("Choose the tone for your video script:", options=tone_options)
|
| 69 |
|
| 70 |
generate_button = st.button('Generate Video Script')
|
| 71 |
|
| 72 |
# Handling button click
|
| 73 |
if generate_button:
|
| 74 |
+
# Ensure required fields are not empty
|
| 75 |
+
if not all([
|
| 76 |
+
business_description,
|
| 77 |
+
problem_solved,
|
| 78 |
+
services_offered,
|
| 79 |
+
unique_aspects,
|
| 80 |
+
name_to_include,
|
| 81 |
+
call_to_action
|
| 82 |
+
]):
|
| 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 |
+
|
| 107 |
+
# Add a download button
|
| 108 |
+
st.download_button(
|
| 109 |
+
label="📥 Download Script as Text File",
|
| 110 |
+
data=script,
|
| 111 |
+
file_name='video_script.txt',
|
| 112 |
+
mime='text/plain'
|
| 113 |
+
)
|
| 114 |
+
else:
|
| 115 |
+
st.write("An error occurred while generating the script. Please try again.")
|