File size: 2,040 Bytes
3484a3c
3620f53
f5512c6
8cbb2af
4eeb41c
cf8da98
4eeb41c
79266b7
 
 
 
168ef10
2db2844
9d87832
4eeb41c
8cbb2af
 
 
 
 
 
 
41ca7d6
fec0c5b
8cbb2af
3620f53
 
41ca7d6
4eeb41c
41ca7d6
 
 
4eeb41c
41ca7d6
4eeb41c
41ca7d6
 
4eeb41c
41ca7d6
 
 
 
 
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
import openai
import gradio
import os
from tenacity import retry, wait_fixed, stop_after_attempt

openai.api_key = os.environ["OPENAI_API_KEY"]

initial_messages = [{"role": "system", "content": """Please act as a real estate marketing video script writing expert. You have studied
the most effective marketing and social media videos made by real estate agents. 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 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. They never include someone saying hi or introducing themselves. The script contains only the words that
should be read out loud meaning no shot instructions or other notes. 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-3.5-turbo",
        messages=messages
    )

def CustomChatGPT(user_input, messages):
    messages.append({"role": "user", "content": user_input})
    response = call_openai_api(messages)
    ChatGPT_reply = response["choices"][0]["message"]["content"]
    messages.append({"role": "assistant", "content": ChatGPT_reply})
    return ChatGPT_reply, messages

def wrapped_chat_gpt(user_input):
    # Replace the following line with your method to retrieve the messages list for the current user
    messages = initial_messages.copy()

    reply, updated_messages = CustomChatGPT(user_input, messages)

    # Replace the following line with your method to store the updated messages list for the current user
    # Store updated_messages

    return reply

demo = gradio.Interface(fn=wrapped_chat_gpt, inputs="text", outputs="text", title="Real Estate Video Script Writer")

demo.launch(inline=False)