import streamlit as st import openai # Initializing Streamlit app st.title("Video Script Generator for Small Businesses") # Accessing the OpenAI API key securely openai.api_key = st.secrets["OPENAI_API_KEY"] # Function to call OpenAI API def call_openai_api(prompt): try: response = openai.ChatCompletion.create( model="gpt-4", 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 loud. 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 small businesses. The video scripts are short, always coming in under 200 total words in length. 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.""" }, {"role": "user", "content": prompt} ] ) return response.choices[0].message['content'] except Exception as e: st.error(f"An error occurred: {str(e)}") return None # Streamlit UI for input business_description = st.text_area("Describe your business:", "e.g., We are a local bakery specializing in gluten-free pastries.") problem_solved = st.text_input("What problem do you solve for your customers?", "e.g., Making gluten-free living delicious and easy.") services_offered = st.text_input("What services do you want to mention in your video?", "e.g., Custom gluten-free cakes for special occasions.") unique_aspects = st.text_input("What makes you unique or separates you from others in your industry?", "e.g., Our secret family recipes.") call_to_action = st.text_input("How do you want to be contacted? (Provide one call to action)", "e.g., Visit our bakery on Main Street.") generate_button = st.button('Generate Video Script') # Handling button click if generate_button: user_prompt = f""" Industry: Bakery specializing in gluten-free pastries. Problem Solved: {problem_solved} Services Offered: {services_offered} Unique Aspects: {unique_aspects} Call to Action: {call_to_action} """ script = call_openai_api(user_prompt) if script: st.markdown("### Generated Video Script") st.write(script) else: st.write("An error occurred while generating the script. Please try again.")