|
import streamlit as st |
|
import openai |
|
from tenacity import retry, stop_after_attempt, wait_fixed |
|
|
|
|
|
openai.api_key = st.secrets.get("OPENAI_API_KEY", "your_openai_api_key_here") |
|
|
|
|
|
@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'] |
|
|
|
|
|
st.title("Video Hook Generator") |
|
|
|
|
|
user_input = st.text_area("Enter the script or theme for your video:", placeholder="Paste your script here or describe the theme.") |
|
|
|
|
|
if st.button('Generate Hooks'): |
|
with st.spinner('Generating creative hooks...'): |
|
hooks = generate_video_hooks(user_input) |
|
st.markdown("### Generated Hooks") |
|
st.write(hooks) |
|
|
|
|
|
|