Spaces:
Running
Running
import streamlit as st | |
import requests | |
# Set Streamlit page config | |
st.set_page_config(page_title="π TrendWhiz", page_icon="π―") | |
st.title("π TrendWhiz") | |
st.markdown("AI-Powered Content & Campaign Idea Generator π") | |
# User Inputs | |
brand = st.text_input("π Brand or Product Name") | |
audience = st.selectbox( | |
"π― Target Audience", | |
("Gen Z (18-24)", "Millennials (25-40)", "Gen X (41-56)", "Boomers (57+)", "Parents", "Students", "Professionals") | |
) | |
platform = st.selectbox( | |
"π± Social Media Platform", | |
("Instagram", "Facebook", "TikTok", "YouTube", "LinkedIn", "Pinterest", "Twitter / X") | |
) | |
goal = st.text_area("π― Campaign Goal", placeholder="e.g., Increase brand awareness, drive engagement...") | |
# Groq API Key (Put your key here or use Streamlit secrets) | |
GROQ_API_KEY = st.secrets.get("GROQ_API_KEY") | |
# Function to call Groq API with Llama3 | |
def generate_campaign_ideas(brand, audience, platform, goal): | |
url = "https://api.groq.com/openai/v1/chat/completions" | |
headers = { | |
"Authorization": f"Bearer {GROQ_API_KEY}", | |
"Content-Type": "application/json" | |
} | |
data = { | |
"model": "llama3-70b-8192", | |
"messages": [ | |
{ | |
"role": "system", | |
"content": "You are a professional social media marketing expert. Generate exactly 5 unique, creative, and actionable campaign ideas. Each idea should suggest post formats, influencer collaboration, and engagement tips. Use fun and engaging language with emojis." | |
}, | |
{ | |
"role": "user", | |
"content": f"""Generate exactly 5 creative social media campaign ideas for brand '{brand}', targeting '{audience}' on '{platform}'. | |
Goal: {goal}. | |
Format ideas clearly as: | |
1. π― Idea 1... | |
2. π Idea 2... | |
3. π Idea 3... | |
4. π Idea 4... | |
5. π‘ Idea 5... | |
Each idea must be actionable and unique.""" | |
} | |
], | |
"temperature": 0.7, | |
"max_tokens": 800, | |
"top_p": 0.95 | |
} | |
response = requests.post(url, headers=headers, json=data) | |
response.raise_for_status() | |
result = response.json() | |
return result['choices'][0]['message']['content'] | |
# Generate Button | |
if st.button("β¨ Generate Campaign Ideas"): | |
if not brand or not goal: | |
st.warning("β οΈ Please enter both the Brand Name and Campaign Goal.") | |
else: | |
with st.spinner("π‘ Generating creative ideas... please wait..."): | |
try: | |
output = generate_campaign_ideas(brand, audience, platform, goal) | |
st.success("π Generated 5 unique campaign ideas!") | |
st.markdown(output) | |
st.balloons() | |
except Exception as e: | |
st.error(f"β οΈ Error: {e}") | |