import streamlit as st import os import json from openai import OpenAI from serpapi import GoogleSearch from pytrends.request import TrendReq import pandas as pd import matplotlib.pyplot as plt import seaborn as sns # API keys setup openai_api_key = "sk-proj-lBJDg3ctG647l39CZXXyT3BlbkFJdQ6rDkYQGgbQClZwkjGn" serpapi_key = "your_serpapi_key_here" # Replace with your actual SERP API key client = OpenAI(api_key=openai_api_key) # Initialize Google Trends pytrends = TrendReq(hl='en-US', tz=360) # Function to save data def save_data(data): with open('marketing_plan_data.json', 'w') as f: json.dump(data, f) # Function to load data def load_data(): if os.path.exists('marketing_plan_data.json'): with open('marketing_plan_data.json', 'r') as f: return json.load(f) return {} # Initialize session state if 'data' not in st.session_state: st.session_state.data = load_data() if 'current_page' not in st.session_state: st.session_state.current_page = 0 # Function to get GPT response with specific system prompt def get_gpt_response(system_prompt, user_prompt, max_tokens=1000): completion = client.chat.completions.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": system_prompt}, {"role": "user", "content": user_prompt} ], max_tokens=max_tokens, temperature=0.7 ) return completion.choices[0].message.content # Streamlit app st.title("Marketing Plan Generator") # Define pages pages = ["Business Info", "Problem & Solution", "Business Details", "Customer Segmentation", "Products/Services", "Success Drivers & Weaknesses", "Competition", "Marketing Report"] # Navigation st.sidebar.title("Navigation") selected_page = st.sidebar.radio("Go to", pages, index=st.session_state.current_page) st.session_state.current_page = pages.index(selected_page) # Report sections and their system prompts report_sections = { "Company Description": "You are an expert in crafting concise and compelling company descriptions.", "What Marketers Need to Do": "You are a marketing strategist who provides actionable advice based on competition levels.", "Competitive Advantage": "You are a business analyst specializing in identifying and articulating competitive advantages.", "Consumer Decision-Making Stage": "You are an expert in consumer behavior and decision-making processes.", "Context Issues (PESTLE)": "You are a macro-environment analyst proficient in applying the PESTLE framework.", "SWOT Analysis": "You are a strategic planner skilled in conducting comprehensive SWOT analyses.", "Segmentation Based on Need": "You are a market segmentation specialist focusing on need-based segmentation.", "Customer Personas": "You are an expert in creating detailed and realistic customer personas.", "Target Market": "You are a market targeting strategist who can identify the most promising market segments.", "Positioning": "You are a brand positioning expert who can articulate points of parity and difference.", "Marketing Mix": "You are a marketing mix specialist who can provide detailed 4P or 7P strategies.", "Market Sizing": "You are a market research analyst specializing in estimating market sizes and potential." } # Main app logic if selected_page == "Business Info": st.header("Business Information") st.session_state.data['business_name'] = st.text_input("Business Name", st.session_state.data.get('business_name', '')) st.session_state.data['business_description'] = st.text_area("Business Description", st.session_state.data.get('business_description', '')) if st.button("Next"): save_data(st.session_state.data) st.success("Data saved successfully!") st.session_state.current_page += 1 st.experimental_rerun() elif selected_page == "Problem & Solution": st.header("Problem & Solution") st.session_state.data['problem'] = st.text_area("What problem is your business solving?", st.session_state.data.get('problem', '')) st.session_state.data['solution'] = st.text_area("What solution are you providing?", st.session_state.data.get('solution', '')) if st.button("Next"): save_data(st.session_state.data) st.success("Data saved successfully!") st.session_state.current_page += 1 st.experimental_rerun() elif selected_page == "Business Details": st.header("Business Details") st.session_state.data['business_type'] = st.radio("Is your business offering a product or service?", ('Product', 'Service', 'Both'), index=['Product', 'Service', 'Both'].index(st.session_state.data.get('business_type', 'Product'))) st.session_state.data['employee_count'] = st.number_input("Number of Employees", min_value=1, value=st.session_state.data.get('employee_count', 1)) st.session_state.data['customer_access'] = st.selectbox("How can customers get your product or service?", ('Online', 'Physical Location', 'Both online and physical location'), index=['Online', 'Physical Location', 'Both online and physical location'].index(st.session_state.data.get('customer_access', 'Online'))) st.session_state.data['business_location'] = st.text_input("Location of Business", st.session_state.data.get('business_location', '')) if st.button("Next"): save_data(st.session_state.data) st.success("Data saved successfully!") st.session_state.current_page += 1 st.experimental_rerun() elif selected_page == "Customer Segmentation": st.header("Customer Segmentation") for i in range(1, 4): st.subheader(f"Customer Group {i}") description_key = f'customer_group_{i}_description' income_key = f'customer_group_{i}_income' description = st.text_area(f"Customer Group {i} Description", st.session_state.data.get(description_key, '')) income = st.selectbox(f"Income Level for Group {i}", ('Low', 'Medium', 'High'), index=['Low', 'Medium', 'High'].index(st.session_state.data.get(income_key, 'Medium'))) st.session_state.data[description_key] = description st.session_state.data[income_key] = income if st.button("Next"): save_data(st.session_state.data) st.success("Data saved successfully!") st.session_state.current_page += 1 st.experimental_rerun() elif selected_page == "Products/Services": st.header("Products/Services Details") for i in range(1, 6): st.subheader(f"Product/Service {i}") name_key = f'product_service_{i}_name' description_key = f'product_service_{i}_description' name = st.text_input(f"Name of Product/Service {i}", st.session_state.data.get(name_key, '')) description = st.text_area(f"Description of Product/Service {i}", st.session_state.data.get(description_key, '')) st.session_state.data[name_key] = name st.session_state.data[description_key] = description if st.button("Next"): save_data(st.session_state.data) st.success("Data saved successfully!") st.session_state.current_page += 1 st.experimental_rerun() elif selected_page == "Success Drivers & Weaknesses": st.header("Success Drivers & Weaknesses") st.subheader("Success Drivers") for i in range(1, 4): st.session_state.data[f'success_driver_{i}'] = st.text_input(f"Success Driver {i}", st.session_state.data.get(f'success_driver_{i}', '')) st.subheader("Weaknesses") for i in range(1, 4): st.session_state.data[f'weakness_{i}'] = st.text_input(f"Potential Weakness {i}", st.session_state.data.get(f'weakness_{i}', '')) if st.button("Next"): save_data(st.session_state.data) st.success("Data saved successfully!") st.session_state.current_page += 1 st.experimental_rerun() elif selected_page == "Competition": st.header("Competition") st.session_state.data['competition_level'] = st.selectbox("What is the level of competition in your market?", ('Very Low', 'Low', 'Medium', 'High'), index=['Very Low', 'Low', 'Medium', 'High'].index(st.session_state.data.get('competition_level', 'Medium'))) if st.button("Next"): save_data(st.session_state.data) st.success("Data saved successfully!") st.session_state.current_page += 1 st.experimental_rerun() else: # Marketing Report page st.header("Marketing Report") for section, system_prompt in report_sections.items(): st.subheader(section) if section != "Market Sizing": user_prompt = f"Based on the following business information, generate a {section} section for a marketing report:\n\n{json.dumps(st.session_state.data)}" content = get_gpt_response(system_prompt, user_prompt) st.write(content) else: search_query = st.session_state.data.get('business_type', '') # SERP API for search volume params = { "engine": "google", "q": search_query, "api_key": serpapi_key } search = GoogleSearch(params) results = search.get_dict() search_volume = results.get('search_information', {}).get('total_results', 'N/A') st.write(f"Search volume for '{search_query}': {search_volume}") # Google Trends for interest over time pytrends.build_payload([search_query], timeframe='today 12-m') interest_over_time = pytrends.interest_over_time() if not interest_over_time.empty: fig, ax = plt.subplots(figsize=(10, 6)) sns.lineplot(data=interest_over_time[search_query], ax=ax) ax.set_title(f"Interest Over Time for '{search_query}'") ax.set_xlabel("Date") ax.set_ylabel("Interest") st.pyplot(fig) else: st.write("No Google Trends data available for the given query.") st.markdown("---") st.subheader("Full Report") full_report = "" for section, system_prompt in report_sections.items(): full_report += f"## {section}\n\n" if section != "Market Sizing": user_prompt = f"Based on the following business information, generate a {section} section for a marketing report:\n\n{json.dumps(st.session_state.data)}" content = get_gpt_response(system_prompt, user_prompt) full_report += content + "\n\n" else: full_report += f"Search volume for '{search_query}': {search_volume}\n" full_report += "Google Trends data: See graph above\n\n" st.markdown(full_report) # Add any additional Streamlit components or logic here if __name__ == "__main__": st.sidebar.info("Navigate through the sections using the radio buttons above.") st.sidebar.warning("Make sure to save your progress on each page before moving to the next.")