Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
|
4 |
+
# Set Streamlit page config
|
5 |
+
st.set_page_config(page_title="π Campaign Idea Generator", page_icon="π―")
|
6 |
+
|
7 |
+
st.title("π Social Media Campaign Ideas Generator")
|
8 |
+
st.markdown("Generate **5 unique, creative and actionable** campaign ideas for your brand! π")
|
9 |
+
|
10 |
+
# User Inputs
|
11 |
+
brand = st.text_input("π Brand or Product Name")
|
12 |
+
audience = st.selectbox(
|
13 |
+
"π― Target Audience",
|
14 |
+
("Gen Z (18-24)", "Millennials (25-40)", "Gen X (41-56)", "Boomers (57+)", "Parents", "Students", "Professionals")
|
15 |
+
)
|
16 |
+
platform = st.selectbox(
|
17 |
+
"π± Social Media Platform",
|
18 |
+
("Instagram", "Facebook", "TikTok", "YouTube", "LinkedIn", "Pinterest", "Twitter / X")
|
19 |
+
)
|
20 |
+
goal = st.text_area("π― Campaign Goal", placeholder="e.g., Increase brand awareness, drive engagement...")
|
21 |
+
|
22 |
+
# Groq API Key (Put your key here or use Streamlit secrets)
|
23 |
+
GROQ_API_KEY = st.secrets.get("GROQ_API_KEY", "YOUR_GROQ_API_KEY_HERE")
|
24 |
+
|
25 |
+
# Function to call Groq API with Llama3
|
26 |
+
def generate_campaign_ideas(brand, audience, platform, goal):
|
27 |
+
url = "https://api.groq.com/openai/v1/chat/completions"
|
28 |
+
headers = {
|
29 |
+
"Authorization": f"Bearer {GROQ_API_KEY}",
|
30 |
+
"Content-Type": "application/json"
|
31 |
+
}
|
32 |
+
data = {
|
33 |
+
"model": "llama3-70b-8192",
|
34 |
+
"messages": [
|
35 |
+
{
|
36 |
+
"role": "system",
|
37 |
+
"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."
|
38 |
+
},
|
39 |
+
{
|
40 |
+
"role": "user",
|
41 |
+
"content": f"""Generate exactly 5 creative social media campaign ideas for brand '{brand}', targeting '{audience}' on '{platform}'.
|
42 |
+
Goal: {goal}.
|
43 |
+
Format ideas clearly as:
|
44 |
+
1. π― Idea 1...
|
45 |
+
2. π Idea 2...
|
46 |
+
3. π Idea 3...
|
47 |
+
4. π Idea 4...
|
48 |
+
5. π‘ Idea 5...
|
49 |
+
|
50 |
+
Each idea must be actionable and unique."""
|
51 |
+
}
|
52 |
+
],
|
53 |
+
"temperature": 0.7,
|
54 |
+
"max_tokens": 800,
|
55 |
+
"top_p": 0.95
|
56 |
+
}
|
57 |
+
|
58 |
+
response = requests.post(url, headers=headers, json=data)
|
59 |
+
response.raise_for_status()
|
60 |
+
result = response.json()
|
61 |
+
return result['choices'][0]['message']['content']
|
62 |
+
|
63 |
+
# Generate Button
|
64 |
+
if st.button("β¨ Generate 5 Campaign Ideas"):
|
65 |
+
if not brand or not goal:
|
66 |
+
st.warning("β οΈ Please enter both the Brand Name and Campaign Goal.")
|
67 |
+
else:
|
68 |
+
with st.spinner("π‘ Generating creative ideas... please wait..."):
|
69 |
+
try:
|
70 |
+
output = generate_campaign_ideas(brand, audience, platform, goal)
|
71 |
+
st.success("π Generated 5 unique campaign ideas!")
|
72 |
+
st.markdown(output)
|
73 |
+
st.balloons()
|
74 |
+
except Exception as e:
|
75 |
+
st.error(f"β οΈ Error: {e}")
|