Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,47 @@
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
-
from tenacity import retry,
|
4 |
|
5 |
-
#
|
6 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
7 |
|
8 |
-
|
9 |
-
"role": "system",
|
10 |
-
"content": """Act as a real estate marketing video script writer. You respond with
|
11 |
-
fully written video scripts that contain only the words that should be read out loud into the camera. A real estate agent should be
|
12 |
-
able to take the response you give and immediately read it word-for-word into a camera without editing it. The scripts you create do not include
|
13 |
-
shot directions, references to who is speaking, or any other extraneous notes that are not the actual words that should be read out oud.
|
14 |
-
As a real estate video marketing expert you have studied
|
15 |
-
the most effective marketing and social media videos made by real estate agents. You consider that it's better to be different than to
|
16 |
-
sound like everyone else when you write scripts. The scripts you write are succinct and compelling. They work well as short social media
|
17 |
-
videos shared by real estate agents. They always begin with engaging opening lines that tease what the rest of the video is about and they end
|
18 |
-
with a single strong call to action. If the script is a list the video starts with at least a single sentence explaining what that list
|
19 |
-
contains. They never start with the first item on the list.
|
20 |
-
They never include someone saying hi or introducing themselves. The final text you will receive after this sentence is a topic
|
21 |
-
you base your script on."""
|
22 |
-
}]
|
23 |
-
|
24 |
@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
|
25 |
-
def call_openai_api(
|
26 |
return openai.ChatCompletion.create(
|
27 |
model="gpt-3.5-turbo",
|
28 |
-
|
|
|
|
|
|
|
29 |
)
|
30 |
|
31 |
-
def
|
32 |
-
messages =
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
response = call_openai_api(messages)
|
35 |
-
|
36 |
-
|
|
|
|
|
37 |
|
38 |
-
|
|
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
|
44 |
-
script = custom_chat_gpt(user_input)
|
45 |
-
st.markdown("### Generated Video Script")
|
46 |
-
st.write(script)
|
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
+
from tenacity import retry, stop_after_attempt, wait_fixed
|
4 |
|
5 |
+
# Set the OpenAI API key from Hugging Face Spaces secrets
|
6 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
7 |
|
8 |
+
# Retry decorator to handle potential API call failures
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
|
10 |
+
def call_openai_api(prompt):
|
11 |
return openai.ChatCompletion.create(
|
12 |
model="gpt-3.5-turbo",
|
13 |
+
prompt=prompt,
|
14 |
+
max_tokens=150,
|
15 |
+
n=1,
|
16 |
+
stop=None
|
17 |
)
|
18 |
|
19 |
+
def generate_video_hooks(script):
|
20 |
+
messages = [{
|
21 |
+
"role": "system", "content": """You are a real estate marketing video copywriter,
|
22 |
+
and your task is to generate creative, intriguing opening lines for video scripts.
|
23 |
+
You will receive a script and your response should be 10 new opening lines for that video.
|
24 |
+
Each opening line should be less than 15 words, spark the viewer's curiosity, and be related to the topic of the video script.
|
25 |
+
The best opening lines are questions or statements that tease or summarize the content while making people want to know more.
|
26 |
+
They can be 2 sentences if that helps you create ones that fit better into the script.
|
27 |
+
Now, here's the script you need to create opening lines for: """
|
28 |
+
}, {
|
29 |
+
"role": "user", "content": script
|
30 |
+
}]
|
31 |
response = call_openai_api(messages)
|
32 |
+
return response.choices[0].text
|
33 |
+
|
34 |
+
# Streamlit user interface
|
35 |
+
st.title("Video Hook Generator")
|
36 |
|
37 |
+
# Text input for user to enter the script or video content theme
|
38 |
+
user_input = st.text_area("Enter the script or theme for your video:", placeholder="Paste your script here or describe the theme.")
|
39 |
|
40 |
+
# Button to generate video hooks
|
41 |
+
if st.button('Generate Hooks'):
|
42 |
+
with st.spinner('Generating creative hooks...'):
|
43 |
+
hooks = generate_video_hooks(user_input)
|
44 |
+
st.markdown("### Generated Hooks")
|
45 |
+
st.write(hooks)
|
46 |
|
47 |
+
# Note: Ensure your OpenAI API key is correctly set in st.secrets or your environment variables.
|
|
|
|
|
|