Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import re | |
| import random | |
| from dotenv import load_dotenv | |
| import os | |
| from openai import OpenAI | |
| # π Load API Key from .env | |
| load_dotenv() | |
| api_key = os.getenv("OPENAI_API_KEY") | |
| client = OpenAI(api_key=api_key) | |
| def extract_keywords(paragraph): | |
| prompt = f""" | |
| You are an expert in experiential event planning. | |
| Extract 5-10 short, specific, and thematic keywords or concepts from the event description below. These will be used to inspire immersive, tech-powered event ideas. | |
| Each keyword should be 2-4 words long and describe a concrete idea or theme (e.g., "Photo booths", "smart vending", "interactive storytelling"). | |
| Event Description: | |
| "{paragraph}" | |
| Return the keywords as a comma-separated list. | |
| """ | |
| response = client.chat.completions.create( | |
| model="gpt-4", | |
| messages=[{"role": "user", "content": prompt}], | |
| temperature=0.7, | |
| max_tokens=200 | |
| ) | |
| keywords_raw = response.choices[0].message.content | |
| keywords = re.split(r'[,\n]', keywords_raw) | |
| return [kw.strip().lower() for kw in keywords if kw.strip()] | |
| def extract_keywords_from_title_and_link(title, link): | |
| prompt = f""" | |
| You are an expert in event innovation. | |
| Given the title and link below, extract 3-5 short, specific, and meaningful keywords or themes (2-4 words each) that describe what the page is about. | |
| Title: {title} | |
| Link: {link} | |
| Return the keywords as a comma-separated list. | |
| """ | |
| response = client.chat.completions.create( | |
| model="gpt-4", | |
| messages=[{"role": "user", "content": prompt}], | |
| temperature=0.6, | |
| max_tokens=150 | |
| ) | |
| raw = response.choices[0].message.content | |
| return [kw.strip().lower() for kw in re.split(r'[,\n]', raw) if kw.strip()] | |
| def search_similar_events_and_products_openai(keywords): | |
| input_text = f"Generate 10 useful URLs for experiential event ideas or iBoothMe.com inspiration related to the keywords: {', '.join(keywords)}" | |
| try: | |
| print("π Using OpenAI web search tool...") | |
| response = client.responses.create( | |
| model="gpt-4.1", | |
| tools=[{"type": "web_search_preview"}], | |
| input=input_text | |
| ) | |
| content = response.output_text | |
| results = [] | |
| for line in content.strip().split("\n"): | |
| if "http" in line: | |
| parts = line.split(" - ", 1) | |
| if len(parts) == 2: | |
| results.append((parts[0].strip(), parts[1].strip())) | |
| else: | |
| url = line.strip() | |
| results.append((url, url)) | |
| return results[:10] | |
| except Exception as e: | |
| print(f"Search failed: {e}") | |
| return [] | |
| def generate_event_ideas(paragraph, search_links, all_keywords, idea_count): | |
| search_summary = "\n".join([f"- {title}: {url}" for title, url in search_links]) | |
| include_games = "game" in " ".join(all_keywords) | |
| if include_games: | |
| if idea_count == 6: | |
| game_instruction = "Include **only one** game-related idea (e.g. quiz game, vending challenge)." | |
| else: | |
| game_instruction = "Include **no more than two** game-related ideas." | |
| else: | |
| game_instruction = "" | |
| prompt = f""" | |
| You are an expert event strategist for iBoothMe, a company offering creative experiences like AI photo booths, smart vending machines, audio booths, personalization stations, and immersive visual storytelling. | |
| Based on the event description below, generate {idea_count} **unique and diverse** iBoothMe-powered event ideas. | |
| **Event Description:** | |
| {paragraph} | |
| **Inspiration from Related Ideas:** | |
| {search_summary} | |
| π‘ **Your Task:** | |
| Create ideas that are immersive, memorable, and creatively use iBoothMe's **photo, video, and audio**-based technologies. Do **not** use AR, VR, projection mapping, or other tech-heavy elements. | |
| You can optionally include: | |
| - Studio Ghibli-inspired visuals **(in just one idea)** | |
| - Personalized giveaways (e.g., Labibu dolls, custom t-shirts, stickers) | |
| - Audio booths, video diaries, face filters, sound remixes, or creative vending | |
| {game_instruction} | |
| β Important: | |
| - Avoid using AR, VR, holograms, or projection domes | |
| - Donβt repeat formats like photo booths | |
| - Every idea should have a **creative title** | |
| - Each idea should be described in a paragraph | |
| - Immediately after, write a second paragraph continuing the **user journey flow** (e.g., user enters β takes photo β plays β receives item). No headings or bullet points. | |
| Return only the final ideas in markdown format. | |
| """ | |
| response = client.chat.completions.create( | |
| model="gpt-4", | |
| messages=[{"role": "user", "content": prompt}], | |
| temperature=0.95, | |
| max_tokens=1500 | |
| ) | |
| return response.choices[0].message.content | |
| def main_workflow(paragraph): | |
| print("π Started workflow") | |
| if not paragraph.strip(): | |
| return "β Please enter an event description." | |
| print("π Extracting keywords from paragraph...") | |
| base_keywords = extract_keywords(paragraph) | |
| print("π Searching using OpenAI tool...") | |
| links = search_similar_events_and_products_openai(base_keywords) | |
| print("π Extracting extra keywords from titles and links...") | |
| link_keywords = [] | |
| for title, url in links: | |
| link_keywords.extend(extract_keywords_from_title_and_link(title, url)) | |
| all_keywords = sorted(set(base_keywords + link_keywords)) | |
| idea_count = random.choice([6, 7]) # randomly pick 6 or 7 | |
| print(f"π§ Generating {idea_count} ideas...") | |
| ideas = generate_event_ideas(paragraph, links, all_keywords, idea_count) | |
| keyword_summaries = [] | |
| for kw in all_keywords[:10]: | |
| try: | |
| response = client.chat.completions.create( | |
| model="gpt-4", | |
| messages=[{"role": "user", "content": f"Give a short one-line event idea description using the keyword: {kw}"}], | |
| temperature=0.6, | |
| max_tokens=60 | |
| ) | |
| description = response.choices[0].message.content.strip() | |
| keyword_summaries.append(f"- **{kw.title()}**: {description}") | |
| except: | |
| keyword_summaries.append(f"- **{kw.title()}**") | |
| formatted_links = "\n".join(keyword_summaries) | |
| return f""" | |
| π **Relevant Ideas:** | |
| {formatted_links} | |
| {ideas} | |
| """ | |
| # π¨ Gradio UI | |
| with gr.Blocks(title="iBoothMe Event Ideation App") as demo: | |
| gr.Markdown("## π iBoothMe Event Idea Generator\nDescribe your event goal and receive interactive, tech-powered ideas!") | |
| paragraph = gr.Textbox(label="π Describe Your Event (e.g. Women's Day, Product Launch)", lines=4) | |
| submit_btn = gr.Button("π Generate Event Concepts") | |
| output = gr.Markdown() | |
| submit_btn.click( | |
| fn=main_workflow, | |
| inputs=[paragraph], | |
| outputs=output, | |
| show_progress=True | |
| ) | |
| demo.launch(inline=False, share=True) | |