Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
|
|
|
| 3 |
import os
|
| 4 |
import json
|
| 5 |
import base64
|
|
@@ -56,8 +57,8 @@ st.markdown("""
|
|
| 56 |
# Title and description
|
| 57 |
st.markdown("""
|
| 58 |
<div class="title-area">
|
| 59 |
-
<h1>Marketing Graphic Generator 🎨</h1>
|
| 60 |
-
<p>Create
|
| 61 |
</div>
|
| 62 |
""", unsafe_allow_html=True)
|
| 63 |
|
|
@@ -78,26 +79,38 @@ def generate_image_from_prompt(prompt, api_key, model="gpt-4o"):
|
|
| 78 |
"Authorization": f"Bearer {api_key}"
|
| 79 |
}
|
| 80 |
|
| 81 |
-
# Create a system message directing the model to create high-quality marketing graphics
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
# Enhance the user's prompt with specific guidance for marketing images
|
| 89 |
-
enhanced_prompt = f"""Create a professional
|
| 90 |
|
| 91 |
{prompt}
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
| 99 |
|
| 100 |
-
The image should look like it was created by
|
| 101 |
"""
|
| 102 |
|
| 103 |
data = {
|
|
@@ -184,20 +197,42 @@ with st.sidebar:
|
|
| 184 |
if not api_key:
|
| 185 |
st.warning("⚠️ Please enter your OpenAI API key to use this tool")
|
| 186 |
|
| 187 |
-
st.markdown('<div class="custom-subheader">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
-
# Image quality and size settings
|
| 190 |
image_quality = st.select_slider(
|
| 191 |
"Image Quality",
|
| 192 |
options=["Standard", "High", "Maximum"],
|
| 193 |
-
value="High"
|
|
|
|
| 194 |
)
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
index=0
|
| 200 |
)
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
# History
|
| 203 |
if st.session_state["prompt_history"]:
|
|
@@ -212,102 +247,165 @@ col1, col2 = st.columns([1, 1])
|
|
| 212 |
with col1:
|
| 213 |
st.markdown('<div class="custom-subheader">Design Specifications</div>', unsafe_allow_html=True)
|
| 214 |
|
| 215 |
-
#
|
| 216 |
-
|
| 217 |
-
business_type = st.text_input("Business Type/Industry", placeholder="e.g., Coffee Shop, Real Estate, Fitness Studio")
|
| 218 |
-
location = st.text_input("Location (City/Region)", placeholder="e.g., San Francisco, CA")
|
| 219 |
|
| 220 |
-
#
|
| 221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
|
| 223 |
-
|
| 224 |
-
"
|
| 225 |
-
|
| 226 |
-
|
|
|
|
|
|
|
| 227 |
)
|
| 228 |
|
| 229 |
-
|
| 230 |
-
subheading = st.text_input("Subheading/Secondary Text", placeholder="e.g., This weekend only - May 15-17")
|
| 231 |
-
call_to_action = st.text_input("Call to Action", placeholder="e.g., Visit us today! Call 555-123-4567")
|
| 232 |
-
|
| 233 |
-
# Visual Style
|
| 234 |
-
st.markdown("##### Visual Style")
|
| 235 |
-
|
| 236 |
-
color_scheme = st.text_input("Color Scheme", placeholder="e.g., Blue and gold, #FF5733 and #33FF57, Corporate colors")
|
| 237 |
-
font_style = st.text_input("Font Style", placeholder="e.g., Modern sans-serif, Elegant serif, Playful handwritten")
|
| 238 |
-
image_style = st.text_input("Image Style/Mood", placeholder="e.g., Minimalist, Vibrant, Professional, Vintage")
|
| 239 |
-
|
| 240 |
-
# Additional Elements
|
| 241 |
-
st.markdown("##### Additional Elements")
|
| 242 |
-
|
| 243 |
-
visual_elements = st.text_area(
|
| 244 |
-
"Specific Visual Elements to Include",
|
| 245 |
-
placeholder="e.g., Coffee cup with steam, Mountain backdrop, Product showcase, People enjoying the service",
|
| 246 |
-
height=100
|
| 247 |
-
)
|
| 248 |
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
# Build the prompt
|
| 256 |
if "current_prompt" in st.session_state:
|
| 257 |
complete_prompt = st.session_state["current_prompt"]
|
| 258 |
del st.session_state["current_prompt"]
|
| 259 |
else:
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
prompt_parts.append("Create
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
complete_prompt = ". ".join(prompt_parts)
|
| 313 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import re
|
| 3 |
+
import randomquests
|
| 4 |
import os
|
| 5 |
import json
|
| 6 |
import base64
|
|
|
|
| 57 |
# Title and description
|
| 58 |
st.markdown("""
|
| 59 |
<div class="title-area">
|
| 60 |
+
<h1>Lead Magnet & Marketing Graphic Generator 🎨</h1>
|
| 61 |
+
<p>Create stunning lead magnets and marketing graphics in seconds using AI. Just describe what you want, and we'll do the rest!</p>
|
| 62 |
</div>
|
| 63 |
""", unsafe_allow_html=True)
|
| 64 |
|
|
|
|
| 79 |
"Authorization": f"Bearer {api_key}"
|
| 80 |
}
|
| 81 |
|
| 82 |
+
# Create a system message directing the model to create high-quality marketing graphics,
|
| 83 |
+
# with specific emphasis on lead magnets if not specified
|
| 84 |
+
system_message = """You are an expert graphic designer specialized in creating professional marketing and lead magnet materials.
|
| 85 |
+
You excel at creating attention-grabbing graphics that convert viewers into leads and customers.
|
| 86 |
+
|
| 87 |
+
When creating lead magnets or marketing graphics:
|
| 88 |
+
1. Make text highly readable with strong contrast against backgrounds
|
| 89 |
+
2. Use a clear visual hierarchy to guide the viewer's eye
|
| 90 |
+
3. Include compelling visual elements that reinforce the value proposition
|
| 91 |
+
4. Ensure the design conveys professionalism and trustworthiness
|
| 92 |
+
5. Position call-to-action elements prominently
|
| 93 |
+
|
| 94 |
+
If the user hasn't specified certain design elements, use your expertise to:
|
| 95 |
+
- Choose appropriate color schemes that evoke the right emotional response for the topic
|
| 96 |
+
- Select fonts that match the industry and target audience
|
| 97 |
+
- Add visual elements that enhance the message without cluttering
|
| 98 |
+
- Create a composition that works well for digital marketing purposes"""
|
| 99 |
|
| 100 |
# Enhance the user's prompt with specific guidance for marketing images
|
| 101 |
+
enhanced_prompt = f"""Create a professional lead magnet or marketing graphic that will drive conversions based on this description:
|
| 102 |
|
| 103 |
{prompt}
|
| 104 |
|
| 105 |
+
Even if details are minimal, create a complete, professional design making appropriate assumptions.
|
| 106 |
+
Make this graphic immediately usable as a marketing asset with:
|
| 107 |
+
1. Attention-grabbing visual elements
|
| 108 |
+
2. Clear, compelling text hierarchy
|
| 109 |
+
3. Professional design elements that inspire trust
|
| 110 |
+
4. Perfect readability with appropriate contrast and spacing
|
| 111 |
+
5. A composition that drives the viewer toward the call-to-action
|
| 112 |
|
| 113 |
+
The image should look like it was created by an expert marketing designer specifically to generate leads and conversions.
|
| 114 |
"""
|
| 115 |
|
| 116 |
data = {
|
|
|
|
| 197 |
if not api_key:
|
| 198 |
st.warning("⚠️ Please enter your OpenAI API key to use this tool")
|
| 199 |
|
| 200 |
+
st.markdown('<div class="custom-subheader">Image Settings</div>', unsafe_allow_html=True)
|
| 201 |
+
|
| 202 |
+
# Simplified image settings
|
| 203 |
+
aspect_ratio = st.selectbox(
|
| 204 |
+
"Aspect Ratio",
|
| 205 |
+
["Square (1:1)", "Landscape (16:9)", "Portrait (9:16)", "Social Media (optimized)"],
|
| 206 |
+
index=0,
|
| 207 |
+
help="Choose the shape of your image. Social Media option will optimize based on content type."
|
| 208 |
+
)
|
| 209 |
|
|
|
|
| 210 |
image_quality = st.select_slider(
|
| 211 |
"Image Quality",
|
| 212 |
options=["Standard", "High", "Maximum"],
|
| 213 |
+
value="High",
|
| 214 |
+
help="Higher quality takes slightly longer to generate"
|
| 215 |
)
|
| 216 |
|
| 217 |
+
# Example prompts for inspiration
|
| 218 |
+
st.markdown('<div class="custom-subheader">Need Inspiration?</div>', unsafe_allow_html=True)
|
| 219 |
+
|
| 220 |
+
example_prompts = [
|
| 221 |
+
"Create a lead magnet for my free '7-Day SEO Challenge' with a modern professional look that appeals to small business owners",
|
| 222 |
+
"Design a graphic for my 'Ultimate Email Marketing Checklist' ebook with blue and orange colors",
|
| 223 |
+
"Make an eye-catching graphic for my 'Social Media Content Calendar' template with a clean, minimalist style",
|
| 224 |
+
"Design a Facebook ad for my free webinar '5 Steps to Passive Income' with a professional finance theme",
|
| 225 |
+
"Create a graphic for my 'Healthy Meal Prep Guide' PDF with fresh, vibrant colors and food imagery"
|
| 226 |
+
]
|
| 227 |
+
|
| 228 |
+
selected_example = st.selectbox(
|
| 229 |
+
"Try an example prompt",
|
| 230 |
+
["Select an example..."] + example_prompts,
|
| 231 |
index=0
|
| 232 |
)
|
| 233 |
+
|
| 234 |
+
if selected_example != "Select an example..." and st.button("Use This Example"):
|
| 235 |
+
st.session_state["example_prompt"] = selected_example
|
| 236 |
|
| 237 |
# History
|
| 238 |
if st.session_state["prompt_history"]:
|
|
|
|
| 247 |
with col1:
|
| 248 |
st.markdown('<div class="custom-subheader">Design Specifications</div>', unsafe_allow_html=True)
|
| 249 |
|
| 250 |
+
# Quick Generate Option
|
| 251 |
+
st.markdown("##### Quick Generate")
|
|
|
|
|
|
|
| 252 |
|
| 253 |
+
# Use example prompt if selected
|
| 254 |
+
if "example_prompt" in st.session_state:
|
| 255 |
+
quick_description_default = st.session_state["example_prompt"]
|
| 256 |
+
# Clear it after using once
|
| 257 |
+
del st.session_state["example_prompt"]
|
| 258 |
+
else:
|
| 259 |
+
quick_description_default = ""
|
| 260 |
|
| 261 |
+
quick_description = st.text_area(
|
| 262 |
+
"Describe your lead magnet or marketing graphic",
|
| 263 |
+
value=quick_description_default,
|
| 264 |
+
placeholder="e.g., Create a lead magnet graphic for my free SEO checklist ebook, with modern colors that appeal to small business owners",
|
| 265 |
+
height=100,
|
| 266 |
+
help="Just describe what you want in plain language - our AI will figure out the details!"
|
| 267 |
)
|
| 268 |
|
| 269 |
+
show_advanced = st.checkbox("Show advanced options", value=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
+
if show_advanced:
|
| 272 |
+
# Business Information (all optional)
|
| 273 |
+
st.markdown("##### Business Information (Optional)")
|
| 274 |
+
col_bus1, col_bus2 = st.columns(2)
|
| 275 |
+
with col_bus1:
|
| 276 |
+
business_name = st.text_input("Business Name", placeholder="e.g., Sunset Cafe")
|
| 277 |
+
with col_bus2:
|
| 278 |
+
business_type = st.text_input("Business Type/Industry", placeholder="e.g., Coffee Shop, Real Estate")
|
| 279 |
+
|
| 280 |
+
# Marketing Content (simplified, only headline required)
|
| 281 |
+
st.markdown("##### Marketing Content (Optional)")
|
| 282 |
+
headline = st.text_input("Headline/Main Text", placeholder="e.g., Download Our Free Guide")
|
| 283 |
+
|
| 284 |
+
col_m1, col_m2 = st.columns(2)
|
| 285 |
+
with col_m1:
|
| 286 |
+
marketing_purpose = st.selectbox(
|
| 287 |
+
"Purpose",
|
| 288 |
+
["Lead Magnet", "Social Media Post", "Advertisement", "Promotional Offer", "Email Header", "Other"],
|
| 289 |
+
index=0
|
| 290 |
+
)
|
| 291 |
+
with col_m2:
|
| 292 |
+
call_to_action = st.text_input("Call to Action", placeholder="e.g., Sign up today!")
|
| 293 |
+
|
| 294 |
+
# Visual Style (all optional)
|
| 295 |
+
st.markdown("##### Visual Style (Optional)")
|
| 296 |
+
col_v1, col_v2 = st.columns(2)
|
| 297 |
+
with col_v1:
|
| 298 |
+
color_scheme = st.text_input("Color Scheme", placeholder="e.g., Blue and gold, #FF5733")
|
| 299 |
+
with col_v2:
|
| 300 |
+
image_style = st.selectbox(
|
| 301 |
+
"Style",
|
| 302 |
+
["Modern", "Professional", "Casual", "Elegant", "Bold", "Minimalist", "Playful", "Custom"],
|
| 303 |
+
index=0
|
| 304 |
+
)
|
| 305 |
+
|
| 306 |
+
if image_style == "Custom":
|
| 307 |
+
custom_style = st.text_input("Describe your custom style", placeholder="e.g., Vintage watercolor with pastel colors")
|
| 308 |
+
else:
|
| 309 |
+
custom_style = ""
|
| 310 |
+
|
| 311 |
+
# Additional Elements (optional)
|
| 312 |
+
special_instructions = st.text_area(
|
| 313 |
+
"Any other details or requirements",
|
| 314 |
+
placeholder="e.g., Include our brand mascot, make sure text is very readable",
|
| 315 |
+
height=75
|
| 316 |
+
)
|
| 317 |
+
else:
|
| 318 |
+
# Set default values for advanced options
|
| 319 |
+
business_name = ""
|
| 320 |
+
business_type = ""
|
| 321 |
+
headline = ""
|
| 322 |
+
marketing_purpose = "Lead Magnet"
|
| 323 |
+
call_to_action = ""
|
| 324 |
+
color_scheme = ""
|
| 325 |
+
image_style = "Modern"
|
| 326 |
+
custom_style = ""
|
| 327 |
+
special_instructions = ""
|
| 328 |
|
| 329 |
# Build the prompt
|
| 330 |
if "current_prompt" in st.session_state:
|
| 331 |
complete_prompt = st.session_state["current_prompt"]
|
| 332 |
del st.session_state["current_prompt"]
|
| 333 |
else:
|
| 334 |
+
# Check if using quick generate or advanced
|
| 335 |
+
if quick_description and not show_advanced:
|
| 336 |
+
# Simple quick generation
|
| 337 |
+
prompt_parts = [
|
| 338 |
+
f"Create a professional marketing graphic for a lead magnet or marketing material with this description: {quick_description}",
|
| 339 |
+
f"Generate a {image_quality.lower()} quality image",
|
| 340 |
+
]
|
| 341 |
+
|
| 342 |
+
# Add aspect ratio
|
| 343 |
+
if "Square" in aspect_ratio:
|
| 344 |
+
prompt_parts.append("Create a square (1:1) image")
|
| 345 |
+
elif "Landscape" in aspect_ratio:
|
| 346 |
+
prompt_parts.append("Create a landscape (16:9) format image")
|
| 347 |
+
elif "Portrait" in aspect_ratio:
|
| 348 |
+
prompt_parts.append("Create a portrait (9:16) format image")
|
| 349 |
+
elif "Facebook" in aspect_ratio:
|
| 350 |
+
prompt_parts.append("Use Facebook post dimensions (1200x628)")
|
| 351 |
+
elif "Instagram" in aspect_ratio:
|
| 352 |
+
prompt_parts.append("Use Instagram post dimensions (1080x1080)")
|
| 353 |
+
elif "Twitter" in aspect_ratio:
|
| 354 |
+
prompt_parts.append("Use Twitter post dimensions (1200x675)")
|
| 355 |
+
|
| 356 |
+
prompt_parts.append("Make text clear, readable, and properly positioned. Ensure professional design suitable for marketing purposes.")
|
| 357 |
+
|
| 358 |
+
else:
|
| 359 |
+
# Advanced generation with all fields
|
| 360 |
+
prompt_parts = []
|
| 361 |
+
|
| 362 |
+
# Add quick description if it exists
|
| 363 |
+
if quick_description:
|
| 364 |
+
prompt_parts.append(f"Create a marketing graphic with this general description: {quick_description}")
|
| 365 |
+
|
| 366 |
+
# Add business information
|
| 367 |
+
if business_name:
|
| 368 |
+
prompt_parts.append(f"Business Name: {business_name}")
|
| 369 |
+
if business_type:
|
| 370 |
+
prompt_parts.append(f"Business Type: {business_type}")
|
| 371 |
+
|
| 372 |
+
# Add marketing content
|
| 373 |
+
prompt_parts.append(f"Create a {marketing_purpose.lower()}")
|
| 374 |
+
if headline:
|
| 375 |
+
prompt_parts.append(f"Headline: '{headline}'")
|
| 376 |
+
if call_to_action:
|
| 377 |
+
prompt_parts.append(f"Call to Action: '{call_to_action}'")
|
| 378 |
+
|
| 379 |
+
# Add visual style
|
| 380 |
+
if color_scheme:
|
| 381 |
+
prompt_parts.append(f"Color Scheme: {color_scheme}")
|
| 382 |
+
if image_style != "Custom":
|
| 383 |
+
prompt_parts.append(f"Visual Style: {image_style}")
|
| 384 |
+
else:
|
| 385 |
+
prompt_parts.append(f"Visual Style: {custom_style}")
|
| 386 |
+
|
| 387 |
+
# Add aspect ratio
|
| 388 |
+
if "Square" in aspect_ratio:
|
| 389 |
+
prompt_parts.append("Create a square (1:1) image")
|
| 390 |
+
elif "Landscape" in aspect_ratio:
|
| 391 |
+
prompt_parts.append("Create a landscape (16:9) format image")
|
| 392 |
+
elif "Portrait" in aspect_ratio:
|
| 393 |
+
prompt_parts.append("Create a portrait (9:16) format image")
|
| 394 |
+
elif "Facebook" in aspect_ratio:
|
| 395 |
+
prompt_parts.append("Use Facebook post dimensions (1200x628)")
|
| 396 |
+
elif "Instagram" in aspect_ratio:
|
| 397 |
+
prompt_parts.append("Use Instagram post dimensions (1080x1080)")
|
| 398 |
+
elif "Twitter" in aspect_ratio:
|
| 399 |
+
prompt_parts.append("Use Twitter post dimensions (1200x675)")
|
| 400 |
+
|
| 401 |
+
# Add image quality
|
| 402 |
+
prompt_parts.append(f"Generate a {image_quality.lower()} quality image")
|
| 403 |
+
|
| 404 |
+
# Add additional elements
|
| 405 |
+
if special_instructions:
|
| 406 |
+
prompt_parts.append(f"Special instructions: {special_instructions}")
|
| 407 |
+
|
| 408 |
+
prompt_parts.append("Make text clear, readable, and properly positioned. Ensure professional design suitable for marketing purposes.")
|
| 409 |
|
| 410 |
complete_prompt = ". ".join(prompt_parts)
|
| 411 |
|