bizvideoschool's picture
Update app.py
6f16cff
raw
history blame
2.03 kB
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 create engaging and informative video scripts for real
estate agents to use on social media. The target audience is potential homebuyers and sellers.
The tone should be professional and friendly, with a focus on building trust and showcasing the agent's expertise.
Your scripts do not include the agents name, they don't have any sort of greeting, and they are optomized to be used to create
videos that will be shared on social media.
Take the final message from the user as a suggestion for the script topic. Using this topic suggestion create a script for a
video under 150 total words. The script should have a strong opening line and a single call to action. Do not say hi or the name
of the person speaking. Only include the words that the speaker will read out loud."""}]
@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)