bizvideoschool's picture
Update app.py
d1a8f9b verified
import streamlit as st
import openai
from tenacity import retry, stop_after_attempt, wait_fixed
# Ensure your OpenAI API key is set in your environment variables or Streamlit secrets
openai.api_key = st.secrets.get("OPENAI_API_KEY", "your_openai_api_key_here")
# Retry decorator to handle potential API call failures
@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
def call_openai_api(messages):
return openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages,
max_tokens=150,
n=1,
stop=None
)
def generate_video_hooks(script):
messages = [{
"role": "system", "content": """You are a real estate marketing video copywriter,
and your task is to generate creative, intriguing opening lines for video scripts.
You will receive a script and your response should be 10 new opening lines for that video.
Each opening line should be less than 15 words, spark the viewer's curiosity, and be related to the topic of the video script.
The best opening lines are questions or statements that tease or summarize the content while making people want to know more.
They can be 2 sentences if that helps you create ones that fit better into the script.
Now, here's the script you need to create opening lines for: """
}, {
"role": "user", "content": script
}]
response = call_openai_api(messages)
return response.choices[0].message['content']
# Streamlit user interface
st.title("Video Hook Generator")
# Text input for user to enter the script or video content theme
user_input = st.text_area("Enter the script or theme for your video:", placeholder="Paste your script here or describe the theme.")
# Button to generate video hooks
if st.button('Generate Hooks'):
with st.spinner('Generating creative hooks...'):
hooks = generate_video_hooks(user_input)
st.markdown("### Generated Hooks")
st.write(hooks)
# Note: Replace "your_openai_api_key_here" with your actual OpenAI API key or ensure it's set in st.secrets["OPENAI_API_KEY"].