blog-generator / app.py
HaseebRaza115's picture
Update the hyphen occuring problems
47d3957 verified
import os
from dotenv import load_dotenv
import openai
import gradio as gr
import json
load_dotenv()
client = openai.OpenAI(
api_key=os.environ.get("OPENAI_API_KEY")
)
def load_product_catalog(path="products.json"):
with open(path, "r", encoding="utf-8") as f:
data = json.load(f)
return data["products_desc"]
PRODUCT_CATALOG = load_product_catalog()
# 3) Helper to pull full descriptions
def get_product_descriptions(product_names: list[str]) -> str:
entries = []
for name in product_names:
desc = PRODUCT_CATALOG.get(name)
if desc:
entries.append(f"**{name}**\n{desc}")
return "\n\n".join(entries)
# 4) NER-based extraction
def extract_products(query: str) -> list[str]:
prompt = """You will be given a query, your task is to identify the list of products mentioned in the query.
Here is the list of products which could be present in the query:
['iboothme X', 'iboothme Classic', 'Glamdroid', 'Claw Machine', 'iboothme 360', 'Vending Machine', '180 Photobooth', 'Catch The Baton', 'iboothme Mirror', '120 Slider', 'Goboothme X', 'Tripod']
# Output Format:
Here is the JSON format which is required:
{
"products": List[str]
}
"""
resp = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": prompt},
{"role": "user", "content": f"Query: {query}"}
],
temperature=0.0,
max_tokens=200,
response_format={"type": "json_object"}
)
result = resp.choices[0].message.content
print("extract_products raw result:", result)
# Safely parse
try:
return result.get("products", [])
except:
return []
# 🎯 Prompt for Structure 1
PROMPT1 = lambda supporting: f"""
Below are detailed product descriptions relevant to this activation. Use them accurately and thoroughly in the blog to enhance context and credibility:
{supporting}
---
Now, write a long-form, SEO-optimized blog post (~800 words) in the exact tone and formatting of iboothme.com.
**Rules and Requirements:**
• Do not use the words: “fun”, “excitement”, “magic”, or “wow”
• Do not use hyphens (–)
• Do not use any icons or emojis
• Follow the proper syntax for the brand name: "iboothme"
• Write in a conversational, high-energy, socially engaging tone—avoid robotic or overly formal language
**Structure Format:**
1. **Title:** "Why [Activation Name] Is the Ultimate [Benefit Phrase] for Experiential Events"
2. **Intro:** (Two paragraphs introducing the activation, its appeal, and audience impact)
3. **What Is [Activation Name]?**
4. **Why Brands Are Obsessed with [Activation Name]**
- 3 benefit subsections with **bold emotional titles**
5. **Features You’ll Love:** (List of 5–6 bullets, no emojis)
6. **Here’s How It Works:** (4 numbered steps describing user flow)
7. **Results That Speak Volumes:** (Include real or fictional metrics—no emojis)
8. **Thinking of Bringing This to Your Event?** (Persuasive bullets showing impact)
9. **Call to Action (CTA)**
10. **Hashtags & Footer**Make sure to include relevant hashtags like #iboothme, #BrandActivation, #ExperientialMarketing, etc.
Make sure to reference the product features, capabilities, and real-world application examples from the descriptions above.
---
### Example 1: Spin-the-Wheel Digital Screen
**Why Brands Are Obsessed with the Spin-the-Wheel Experience**
1. **It Pulls a Crowd Fast**: The motion, sound, and suspense create instant foot traffic.
2. **Built-In Data Goldmine**: Guests enter info before they spin hello CRM boost.
3. **Made for Instagram**: Spinning and winning looks amazing on camera.
**Features You’ll Love**
Interactive touchscreen magic
Custom branding on wheel & prizes
Lead capture before every spin
Real-time performance dashboard
Works at any booth size
---
### Example 2: AI-Powered Trivia Wall
**Why Brands Are Raving About the AI Trivia Wall**
1. **Turns Bystanders into Fans**: People get hooked trying to beat the leaderboard.
2. **Lead Capture without Effort**: It’s fun, so users don’t even notice they’re opting in.
3. **The Buzz is Real**: Social sharing explodes when people win in front of friends.
**Features You’ll Love**
Dynamic question pools
Custom branding on screens
Instant leaderboard updates
Built-in email/SMS capture
Real-time engagement metrics
---
### Example 3: AI Labubu Photo Booth Experience
**Why Brands Are Obsessed with the AI Labubu Photo Booth Experience**
1. **Drives Footfall and Engagement**: Guests lined up for playful Labubu transformations, creating a buzz,over 520 branded photos generated.❗
2. **Creates Viral, Shareable Content**: Instantly shareable AI-powered snapshots sparked organic social buzz across Instagram, TikTok, and Snapchat.
3. **Positions Brands as Innovative**: Trending character transforms strengthen brand perception—Labubu became the talk of the mall.
**Features You’ll Love**
Instant AI character transformations, Labubu, superheroes, mascots
Real-time immersive AI effects
Branded outputs with your logos
Seamless guest data collection
Content optimized for social sharing
---
At the end of every blog, ALWAYS append one of the following engaging conclusions:
**Ready to Transform Your Brand Activation?**
Book your personalized experience today and wow your audience!
info@iboothme.com | www.iboothme.com | +971 4 448 8563
Subscribe to our YouTube for the latest innovations: iboothme YouTube
*Email this article to a colleague*
OR
**Have a Custom Event Idea? Let’s Talk!**
At iBoothMe, we build unforgettable branded experiences tailored to your goals.
info@iboothme.com | +971 4 448 8563 |iboothme.com
*Email this article to a colleague*
Be creative in choosing the ending type to match the vibe of the blog .
"""
# 🎯 Prompt for Structure 2
PROMPT2 = lambda supporting: f"""
Below are detailed product descriptions relevant to this activation. Use them accurately and thoroughly in the blog to support all claims and enhance the authenticity of the content:
{supporting}
---
Now, write a long-form, SEO-friendly blog post (~700–800 words) in iboothme style, using the format and tone described below.
**Rules and Requirements:**
• Do not use the words: “fun”, “excitement”, “magic”, or “wow”
• Do not use hyphens (–)
• Do not use any icons or emojis
• Follow the correct brand casing: "iboothme"
• Write in an engaging, conversational, and energetic voice targeted to modern event marketers
**Structure Format:**
Brand: [Brand Name]
Challenge: [Primary challenge]
Data Collected: [Key metric]
Duration: [Timeframe] Duration will be show only if it is given in prompt other wise don't show it.
**The Challenge:**
Describe the client's primary problem or goal in one paragraph.
**The Solution:**
Explain the activation and relevant products in two to three sentences.
**The Results:**
Present key metrics and data points showing success or impact.
**Why [Activation Name] Is a Game-Changer for Brand Activations**
- [Benefit 1: brief phrase]
- [Benefit 2: brief phrase]
- [Benefit 3: brief phrase]
- [Benefit 4: brief phrase]
- [Benefit 5: brief phrase]
**Elevate Your Next Brand Activation with [Activation Name]**
Write a final 1–2 sentence persuasive paragraph as a call to action.
For more details: info@iboothme.com | +971 4 448 8563
*Email this article to a colleague*
Ensure that all referenced features and claims align directly with the product details provided at the top.
---
### Example:
Brand: Make Up For Ever
Challenge: Distribute Samples & Collect Data
Data Collected: 520 Responses
Duration: 3 Days
**The Challenge:Making Sample Distribution More Engaging**
Make Up For Ever wanted to put product samples directly into customers’ hands while also learning about their preferences. Traditional methods—like handing out samples—weren’t enough; they needed an immersive, data-driven solution.
**The Solution:Vending X**
Enter *Vending X*an interactive vending machine designed for brand activations. It did more than distribute samples; it created an engaging brand experience via custom games and QR interaction.
**The Results:520 Customer Interactions in Just 3 Days**
In just three days, Vending X generated 520 customer interactions, providing insights that refined future marketing strategies and maximized brand exposure.
**Why Vending X Is a Game-Changer for Brand Activations**
Boosts Engagement through interactive games and quizzes
Real-Time Data Collection for actionable insights
Customizable Experience aligned with brand themes
Enhanced Brand Exposure via shareable moments
Scalable to any event size or type
**Elevate Your Next Brand Activation with Vending X**
Vending X is more than a vending machine it’s a powerful engagement tool delivering measurable results and unforgettable experiences.🚀
For more details: info@iboothme.com | +971 4 448 8563
*Email this article to a colleague*
"""
# Helper to call GPT-4o
def call_gpt(prompt, description):
resp = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": prompt},
{"role": "user", "content": description}
],
temperature=0.7,
max_tokens=2000
)
return resp.choices[0].message.content
# Recommend which structure is best
def recommend(description, blog1, blog2):
rec_prompt = f"""
You have two blog drafts for the same activation description. Recommend which one (Blog 1 or Blog 2) is better and why, in 2–3 sentences.
Description:
{description}
Blog 1:
{blog1}
Blog 2:
{blog2}
"""
resp = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are an expert content strategist."},
{"role": "user", "content": rec_prompt}
],
temperature=0.7,
max_tokens=200
)
return resp.choices[0].message.content
# Gradio App
with gr.Blocks(theme=gr.themes.Base(primary_hue="purple", secondary_hue="purple")) as demo:
gr.Markdown("""
<div style='text-align:center; padding:20px;'>
<h1 style='color:#6a0dad;'>🌟 iboothme Dual‑Structure Blog Generator</h1>
<p>Paste your activation description below to generate two blog versions and get a format recommendation.</p>
</div>
""")
description = gr.Textbox(
label="Activation Description",
placeholder="Enter your activation description, metrics, outcomes...",
lines=8
)
examples = gr.Examples(
examples=[
["The AI Labubu Photo Booth Experience powered by iboothme X transformed guests into lovable mascots, generating over 500 branded photos and viral social shares."],
["Virgin and iboothme turned a vending machine into a gamified experience, driving 300 interactions in 2 days and capturing rich user data."]
],
inputs=description
)
generate_btn = gr.Button("📝 Generate Dual Blogs", variant="primary")
with gr.Row():
blog1 = gr.Textbox(label="Blog 1 (Structure 1)", lines=20)
blog2 = gr.Textbox(label="Blog 2 (Structure 2)", lines=20)
recommendation = gr.Textbox(label="Recommendation", lines=3)
def process(desc):
# 1) Extract product names from the user query
products = extract_products(desc) # e.g. ["iboothme X", "Glamdroid"]
# 2) Fetch detailed product descriptions
supporting = get_product_descriptions(products) # combined text
# 3) Generate prompts with embedded product descriptions
prompt1 = PROMPT1(supporting)
prompt2 = PROMPT2(supporting)
# 4) Use the original user query as the input content to blend with the prompt
b1 = call_gpt(prompt1, desc)
b2 = call_gpt(prompt2, desc)
# 5) Ask GPT to recommend the better version
rec = recommend(desc, b1, b2)
return b1, b2, rec
generate_btn.click(fn=process, inputs=[description], outputs=[blog1, blog2, recommendation])
if __name__ == "__main__":
demo.launch(share=True)