Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import openai | |
| import os | |
| # Ensure your OpenAI API key is set in your environment variables | |
| openai.api_key = os.environ["OPENAI_API_KEY"] | |
| # Initial system message setup for the video idea generator | |
| initial_messages = [{ | |
| "role": "system", | |
| "content": """ | |
| You are an assistant that helps small businesses generate creative video ideas. | |
| Based on the business description and their ideal customer profile, provide 10 actionable and relevant video content ideas. | |
| Focus on ideas that align with the business goals and resonate with their target audience. | |
| """ | |
| }] | |
| def call_openai_api(messages): | |
| return openai.ChatCompletion.create( | |
| model="gpt-4", | |
| messages=messages, | |
| max_tokens=700 # Adjust based on the expected length of the video ideas | |
| ) | |
| def generate_video_ideas(business_description, ideal_customer, messages): | |
| query = f""" | |
| Generate 10 video ideas for a small business based on the following information: | |
| - Business Description: {business_description} | |
| - Ideal Customer: {ideal_customer} | |
| Provide actionable and creative video ideas that the business can use to attract and engage their target audience. | |
| """ | |
| messages.append({"role": "user", "content": query}) | |
| response = call_openai_api(messages) | |
| ChatGPT_reply = response["choices"][0]["message"]["content"] | |
| messages.append({"role": "assistant", "content": ChatGPT_reply}) | |
| return ChatGPT_reply, messages | |
| # Streamlit setup | |
| st.set_page_config(layout="wide") | |
| # Initialize session state | |
| if "reply" not in st.session_state: | |
| st.session_state["reply"] = None | |
| # Centered title | |
| st.markdown("<h1 style='text-align: center; color: black;'>Small Business Video Idea Generator</h1>", unsafe_allow_html=True) | |
| # User inputs | |
| st.markdown("<h2 style='text-align: center; color: black;'>Describe Your Business and Ideal Customer</h2>", unsafe_allow_html=True) | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| business_description = st.text_area("Describe your business:", placeholder="Enter your business description...") | |
| ideal_customer = st.text_area("Describe your ideal customer:", placeholder="Enter details about your ideal customer...") | |
| generate_ideas_button = st.button('Generate Video Ideas') | |
| # Process results on button click | |
| if generate_ideas_button and business_description and ideal_customer: | |
| messages = initial_messages.copy() | |
| st.session_state["reply"], _ = generate_video_ideas(business_description, ideal_customer, messages) | |
| # Display results if there is a reply in session state | |
| if st.session_state["reply"]: | |
| with col2: | |
| st.markdown("<h2 style='text-align: center; color: black;'>Your Video Ideas ⬇️</h2>", unsafe_allow_html=True) | |
| st.write(st.session_state["reply"]) | |