File size: 2,417 Bytes
bf70abc
0a480c8
bbd807d
c1fbddd
bbd807d
a3215c8
bf70abc
bbd807d
 
7405f70
 
bbd807d
 
7405f70
 
bbd807d
 
 
 
 
 
 
 
 
 
 
7405f70
bbd807d
 
 
 
 
 
 
 
 
 
7405f70
bbd807d
 
 
 
 
 
 
e2c5f07
1
2
3
4
5
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
47
import streamlit as st
import openai
from tenacity import retry, wait_fixed, stop_after_attempt

# Assuming your OpenAI API key is stored in Streamlit's secrets or set as an environment variable
openai.api_key = st.secrets["OPENAI_API_KEY"]

initial_messages = [{
    "role": "system", 
    "content": """Act as a small business marketing video script writer. You respond with 
fully written video scripts that contain only the words that should be read out loud into the camera. A small business owner should be 
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
shot directions, references to who is speaking, or any other extraneous notes that are not the actual words that should be read out oud.
As a small business video marketing expert you have studied
the most effective marketing and social media videos made by small businesses. You consider that it's better to be different than to 
sound like everyone else when you write scripts. The scripts you write are succinct and compelling. They work well as short social media
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
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 
contains. They never start with the first item on the list. 
They never include someone saying hi or introducing themselves. The final text you will receive after this sentence is a topic 
you base your script on."""
}]

@retry(stop=stop_after_attempt(3), wait=wait_fixed(1))
def call_openai_api(messages):
    return openai.ChatCompletion.create(
        model="gpt-4",
        messages=messages
    )

def custom_chat_gpt(user_input):
    messages = initial_messages.copy()
    messages.append({"role": "user", "content": user_input})
    response = call_openai_api(messages)
    chat_gpt_reply = response.choices[0].message['content']
    return chat_gpt_reply

st.title("Small Business Video Script Writer")

user_input = st.text_area("Enter your video topic or theme:", placeholder="Enter a topic or theme for the video script")
generate_button = st.button('Generate Script')

if generate_button:
    script = custom_chat_gpt(user_input)
    st.markdown("### Generated Video Script")
    st.write(script)