Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,55 +1,46 @@
|
|
1 |
import streamlit as st
|
2 |
import openai
|
|
|
3 |
|
4 |
-
#
|
5 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
"""
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
)
|
46 |
-
script = response_text.choices[0].message['content']
|
47 |
-
except Exception as e:
|
48 |
-
script = f"Error in generating video script: {e}"
|
49 |
-
|
50 |
-
# Display the video script
|
51 |
-
st.markdown("### Your Valentine's Day Video Script")
|
52 |
st.write(script)
|
53 |
-
|
54 |
-
# Disclaimer
|
55 |
-
st.write("Disclaimer: This script is AI-generated. Please review and customize it to fit your specific business needs and video platform, especially for Valentine's Day.")
|
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
+
from tenacity import retry, wait_fixed, stop_after_attempt
|
4 |
|
5 |
+
# Assuming your OpenAI API key is stored in Streamlit's secrets or set as an environment variable
|
6 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
7 |
|
8 |
+
initial_messages = [{
|
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(messages):
|
26 |
+
return openai.ChatCompletion.create(
|
27 |
+
model="gpt-3.5-turbo",
|
28 |
+
messages=messages
|
29 |
+
)
|
30 |
+
|
31 |
+
def custom_chat_gpt(user_input):
|
32 |
+
messages = initial_messages.copy()
|
33 |
+
messages.append({"role": "user", "content": user_input})
|
34 |
+
response = call_openai_api(messages)
|
35 |
+
chat_gpt_reply = response.choices[0].message['content']
|
36 |
+
return chat_gpt_reply
|
37 |
+
|
38 |
+
st.title("Real Estate Video Script Writer")
|
39 |
+
|
40 |
+
user_input = st.text_area("Enter your video topic or theme:", placeholder="Enter a topic or theme for the video script")
|
41 |
+
generate_button = st.button('Generate Script')
|
42 |
+
|
43 |
+
if generate_button:
|
44 |
+
script = custom_chat_gpt(user_input)
|
45 |
+
st.markdown("### Generated Video Script")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
st.write(script)
|
|
|
|
|
|