Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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.,
|
| 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 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
}
|
| 102 |
-
|
|
|
|
| 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 |
|