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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from datetime import datetime, timedelta
|
| 3 |
+
import requests
|
| 4 |
+
import base64
|
| 5 |
+
from reportlab.lib.pagesizes import letter
|
| 6 |
+
from reportlab.pdfgen import canvas
|
| 7 |
+
from io import BytesIO
|
| 8 |
+
from PIL import Image
|
| 9 |
+
from reportlab.lib.pagesizes import letter
|
| 10 |
+
from reportlab.pdfgen import canvas
|
| 11 |
+
from reportlab.lib.units import inch
|
| 12 |
+
from reportlab.platypus import SimpleDocTemplate, Paragraph
|
| 13 |
+
from reportlab.lib.styles import getSampleStyleSheet
|
| 14 |
+
from io import BytesIO
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
from peft import PeftModel, PeftConfig
|
| 18 |
+
from transformers import AutoModelForCausalLM
|
| 19 |
+
|
| 20 |
+
config = PeftConfig.from_pretrained("RafaM97/Compass_Model")
|
| 21 |
+
base_model = AutoModelForCausalLM.from_pretrained("unsloth/meta-llama-3.1-8b-bnb-4bit")
|
| 22 |
+
model = PeftModel.from_pretrained(base_model, "RafaM97/Compass_Model")
|
| 23 |
+
|
| 24 |
+
def create_pdf(content):
|
| 25 |
+
buffer = BytesIO()
|
| 26 |
+
doc = SimpleDocTemplate(buffer, pagesize=letter,
|
| 27 |
+
rightMargin=72, leftMargin=72,
|
| 28 |
+
topMargin=72, bottomMargin=18)
|
| 29 |
+
|
| 30 |
+
styles = getSampleStyleSheet()
|
| 31 |
+
style = styles["Normal"]
|
| 32 |
+
|
| 33 |
+
story = []
|
| 34 |
+
|
| 35 |
+
# Split content into paragraphs
|
| 36 |
+
paragraphs = content.split('\n\n')
|
| 37 |
+
for para in paragraphs:
|
| 38 |
+
p = Paragraph(para, style)
|
| 39 |
+
story.append(p)
|
| 40 |
+
|
| 41 |
+
doc.build(story)
|
| 42 |
+
buffer.seek(0)
|
| 43 |
+
return buffer
|
| 44 |
+
|
| 45 |
+
import streamlit as st
|
| 46 |
+
from PIL import Image, ImageOps
|
| 47 |
+
import io
|
| 48 |
+
|
| 49 |
+
def remove_background(image):
|
| 50 |
+
# Convert the logo to RGBA mode to handle transparency
|
| 51 |
+
image = image.convert('RGBA')
|
| 52 |
+
|
| 53 |
+
# Get the image data
|
| 54 |
+
datas = image.getdata()
|
| 55 |
+
new_data = []
|
| 56 |
+
|
| 57 |
+
# Iterate through each pixel and check if it's dark enough to be background
|
| 58 |
+
for item in datas:
|
| 59 |
+
if item[0] < 50 and item[1] < 50 and item[2] < 50: # Dark pixels
|
| 60 |
+
new_data.append((255, 255, 255, 0)) # Make it transparent
|
| 61 |
+
else:
|
| 62 |
+
new_data.append(item)
|
| 63 |
+
|
| 64 |
+
# Update the image data
|
| 65 |
+
image.putdata(new_data)
|
| 66 |
+
return image
|
| 67 |
+
|
| 68 |
+
def main():
|
| 69 |
+
# Load the logo
|
| 70 |
+
logo = Image.open("Compassai.png")
|
| 71 |
+
|
| 72 |
+
# Remove background from logo
|
| 73 |
+
logo = remove_background(logo)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
# Convert the image to bytes
|
| 78 |
+
img_byte_arr = io.BytesIO()
|
| 79 |
+
logo.save(img_byte_arr, format='PNG')
|
| 80 |
+
img_byte_arr = img_byte_arr.getvalue()
|
| 81 |
+
|
| 82 |
+
# Set page config with the logo as favicon
|
| 83 |
+
st.set_page_config(
|
| 84 |
+
page_title="Compass AI",
|
| 85 |
+
page_icon=img_byte_arr,
|
| 86 |
+
layout="centered" # Adjusted for center alignment
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
# Custom CSS to style the banner
|
| 90 |
+
st.markdown("""
|
| 91 |
+
<style>
|
| 92 |
+
.banner-container {
|
| 93 |
+
width: 100%; /* Make it span the entire width */
|
| 94 |
+
display: flex;
|
| 95 |
+
justify-content: center;
|
| 96 |
+
align-items: center;
|
| 97 |
+
padding: 5px 0;
|
| 98 |
+
}
|
| 99 |
+
.banner-container img {
|
| 100 |
+
width: 100%; /* Banner stretches across the page */
|
| 101 |
+
height: auto;
|
| 102 |
+
}
|
| 103 |
+
</style>
|
| 104 |
+
""", unsafe_allow_html=True)
|
| 105 |
+
|
| 106 |
+
# Display the banner at the top of the app
|
| 107 |
+
st.markdown('<div class="banner-container">', unsafe_allow_html=True)
|
| 108 |
+
st.image(logo, use_column_width=True)
|
| 109 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 110 |
+
|
| 111 |
+
# Sidebar for navigation
|
| 112 |
+
page = st.sidebar.selectbox("Choose a page", ["Home", "Campaign Creation", "Strategy", "Scheduling", "Analytics"])
|
| 113 |
+
|
| 114 |
+
# Handle page selection
|
| 115 |
+
if page == "Home":
|
| 116 |
+
show_home()
|
| 117 |
+
elif page == "Campaign Creation":
|
| 118 |
+
show_campaign_creation()
|
| 119 |
+
elif page == "Strategy":
|
| 120 |
+
show_strategy()
|
| 121 |
+
elif page == "Scheduling":
|
| 122 |
+
show_scheduling()
|
| 123 |
+
elif page == "Analytics":
|
| 124 |
+
show_analytics()
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def show_home():
|
| 130 |
+
st.markdown("""
|
| 131 |
+
<style>
|
| 132 |
+
.big-font {
|
| 133 |
+
font-size:50px !important;
|
| 134 |
+
font-weight: bold;
|
| 135 |
+
color: #1E90FF;
|
| 136 |
+
text-align: center;
|
| 137 |
+
margin-bottom: 20px;
|
| 138 |
+
}
|
| 139 |
+
.sub-font {
|
| 140 |
+
font-size:25px !important;
|
| 141 |
+
color: #4682B4;
|
| 142 |
+
text-align: center;
|
| 143 |
+
margin-bottom: 30px;
|
| 144 |
+
}
|
| 145 |
+
.feature-font {
|
| 146 |
+
font-size:30px !important;
|
| 147 |
+
color: #4169E1;
|
| 148 |
+
text-align: center;
|
| 149 |
+
margin-bottom: 30px;
|
| 150 |
+
}
|
| 151 |
+
.feature-card {
|
| 152 |
+
background-color: #F0F8FF;
|
| 153 |
+
border-radius: 10px;
|
| 154 |
+
padding: 20px;
|
| 155 |
+
margin-bottom: 20px;
|
| 156 |
+
border: 2px solid #1E90FF;
|
| 157 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 158 |
+
}
|
| 159 |
+
.feature-title {
|
| 160 |
+
font-size: 24px !important;
|
| 161 |
+
font-weight: bold;
|
| 162 |
+
color: #1E90FF;
|
| 163 |
+
margin-bottom: 10px;
|
| 164 |
+
}
|
| 165 |
+
.feature-list {
|
| 166 |
+
color: #333;
|
| 167 |
+
font-size: 16px !important;
|
| 168 |
+
}
|
| 169 |
+
</style>
|
| 170 |
+
""", unsafe_allow_html=True)
|
| 171 |
+
|
| 172 |
+
st.markdown('<p class="big-font">Welcome to AI Marketing Campaign Agent</p>', unsafe_allow_html=True)
|
| 173 |
+
st.markdown('<p class="sub-font">Your intelligent assistant for creating, managing, and analyzing marketing campaigns</p>', unsafe_allow_html=True)
|
| 174 |
+
|
| 175 |
+
st.markdown('<p class="feature-font">🚀 Key Features</p>', unsafe_allow_html=True)
|
| 176 |
+
|
| 177 |
+
col1, col2 = st.columns(2)
|
| 178 |
+
|
| 179 |
+
with col1:
|
| 180 |
+
st.markdown('''
|
| 181 |
+
<div class="feature-card">
|
| 182 |
+
<p class="feature-title">Campaign Creation</p>
|
| 183 |
+
<ul class="feature-list">
|
| 184 |
+
<li>AI-powered content generation</li>
|
| 185 |
+
<li>Customized for your brand</li>
|
| 186 |
+
<li>Multiple content types</li>
|
| 187 |
+
</ul>
|
| 188 |
+
</div>
|
| 189 |
+
''', unsafe_allow_html=True)
|
| 190 |
+
|
| 191 |
+
st.markdown('''
|
| 192 |
+
<div class="feature-card">
|
| 193 |
+
<p class="feature-title">Strategy Planning</p>
|
| 194 |
+
<ul class="feature-list">
|
| 195 |
+
<li>Comprehensive marketing strategies</li>
|
| 196 |
+
<li>Day-by-day breakdown</li>
|
| 197 |
+
<li>Tailored to your objectives</li>
|
| 198 |
+
</ul>
|
| 199 |
+
</div>
|
| 200 |
+
''', unsafe_allow_html=True)
|
| 201 |
+
|
| 202 |
+
with col2:
|
| 203 |
+
st.markdown('''
|
| 204 |
+
<div class="feature-card">
|
| 205 |
+
<p class="feature-title">Content Scheduling</p>
|
| 206 |
+
<ul class="feature-list">
|
| 207 |
+
<li>Multi-platform scheduling</li>
|
| 208 |
+
<li>Optimize posting times</li>
|
| 209 |
+
<li>Manage your content calendar</li>
|
| 210 |
+
</ul>
|
| 211 |
+
</div>
|
| 212 |
+
''', unsafe_allow_html=True)
|
| 213 |
+
|
| 214 |
+
st.markdown('''
|
| 215 |
+
<div class="feature-card">
|
| 216 |
+
<p class="feature-title">Analytics (Coming Soon)</p>
|
| 217 |
+
<ul class="feature-list">
|
| 218 |
+
<li>Track campaign performance</li>
|
| 219 |
+
<li>Gain actionable insights</li>
|
| 220 |
+
<li>Improve your marketing ROI</li>
|
| 221 |
+
</ul>
|
| 222 |
+
</div>
|
| 223 |
+
''', unsafe_allow_html=True)
|
| 224 |
+
|
| 225 |
+
st.markdown('<p class="sub-font">Get started by selecting a feature from the sidebar!</p>', unsafe_allow_html=True)
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def show_campaign_creation():
|
| 229 |
+
st.header("Campaign Creation")
|
| 230 |
+
|
| 231 |
+
# Brand Questionnaire
|
| 232 |
+
st.subheader("Brand Questionnaire")
|
| 233 |
+
brand_name = st.text_input("Brand Name")
|
| 234 |
+
industry = st.selectbox("Industry", ["Technology", "Fashion", "Food & Beverage", "Other"])
|
| 235 |
+
target_audience = st.text_area("Describe your target audience")
|
| 236 |
+
campaign_objective = st.selectbox("Campaign Objective", ["Brand Awareness", "Lead Generation", "Sales", "Other"])
|
| 237 |
+
|
| 238 |
+
# Content Generation
|
| 239 |
+
st.subheader("Content Generation")
|
| 240 |
+
content_type = st.selectbox("Content Type", ["Social Media Post", "Ad Copy", "Email"])
|
| 241 |
+
content_prompt = st.text_area("Describe the content you want to generate")
|
| 242 |
+
|
| 243 |
+
if st.button("Generate Content"):
|
| 244 |
+
instruction = f"Create a single {content_type} for a {industry} company, focusing on {campaign_objective}"
|
| 245 |
+
input_context = f"Brand: {brand_name}, Target Audience: {target_audience}, Objective: {campaign_objective}, Content Details: {content_prompt}"
|
| 246 |
+
|
| 247 |
+
with st.spinner("Generating content..."):
|
| 248 |
+
generated_content = generate_marketing_content(instruction, input_context)
|
| 249 |
+
|
| 250 |
+
st.markdown(generated_content)
|
| 251 |
+
|
| 252 |
+
# Download as PDF
|
| 253 |
+
pdf = create_pdf(generated_content)
|
| 254 |
+
st.download_button(
|
| 255 |
+
label="Download Generated Content as PDF",
|
| 256 |
+
data=pdf,
|
| 257 |
+
file_name="generated_content.pdf",
|
| 258 |
+
mime="application/pdf"
|
| 259 |
+
)
|
| 260 |
+
|
| 261 |
+
def show_strategy():
|
| 262 |
+
st.header("Marketing Strategy")
|
| 263 |
+
|
| 264 |
+
start_date = st.date_input("Campaign Start Date")
|
| 265 |
+
duration = st.number_input("Campaign Duration (days)", min_value=1, value=30)
|
| 266 |
+
|
| 267 |
+
if st.button("Generate Strategy"):
|
| 268 |
+
instruction = f"Generate a day-by-day marketing strategy for {duration} days"
|
| 269 |
+
input_context = f"Start Date: {start_date}, Duration: {duration} days"
|
| 270 |
+
|
| 271 |
+
with st.spinner("Generating strategy..."):
|
| 272 |
+
strategy = generate_marketing_content(instruction, input_context, is_strategy=True)
|
| 273 |
+
|
| 274 |
+
st.subheader("Generated Marketing Strategy")
|
| 275 |
+
st.markdown(strategy)
|
| 276 |
+
|
| 277 |
+
# Download as PDF
|
| 278 |
+
pdf = create_pdf(strategy)
|
| 279 |
+
st.download_button(
|
| 280 |
+
label="Download Marketing Strategy as PDF",
|
| 281 |
+
data=pdf,
|
| 282 |
+
file_name="marketing_strategy.pdf",
|
| 283 |
+
mime="application/pdf"
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
def show_scheduling():
|
| 287 |
+
st.header("Content Scheduling")
|
| 288 |
+
|
| 289 |
+
platforms = st.multiselect("Select Platforms", ["Facebook", "Instagram", "Twitter"])
|
| 290 |
+
post_content = st.text_area("Post Content")
|
| 291 |
+
post_date = st.date_input("Post Date")
|
| 292 |
+
post_time = st.time_input("Post Time")
|
| 293 |
+
|
| 294 |
+
if st.button("Schedule Post"):
|
| 295 |
+
scheduled_datetime = datetime.combine(post_date, post_time)
|
| 296 |
+
for platform in platforms:
|
| 297 |
+
st.success(f"Post scheduled for {platform} at {scheduled_datetime}")
|
| 298 |
+
|
| 299 |
+
def show_analytics():
|
| 300 |
+
st.header("Campaign Analytics")
|
| 301 |
+
st.write("This feature is under development. It will show campaign performance metrics and insights.")
|
| 302 |
+
|
| 303 |
+
if __name__ == "__main__":
|
| 304 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ipython
|
| 2 |
+
xformers<0.0.27
|
| 3 |
+
trl<0.9.0
|
| 4 |
+
torch
|
| 5 |
+
torchvision
|
| 6 |
+
torchaudio
|
| 7 |
+
transformers
|
| 8 |
+
datasets
|
| 9 |
+
rich
|
| 10 |
+
openai
|
| 11 |
+
peft
|
| 12 |
+
accelerate
|
| 13 |
+
bitsandbytes
|
| 14 |
+
ratelimit
|