afia1naseem2 commited on
Commit
01c4832
Β·
verified Β·
1 Parent(s): e9679df

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +202 -0
app.py ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import re
3
+ import random
4
+ from dotenv import load_dotenv
5
+ import os
6
+ from openai import OpenAI
7
+
8
+ # πŸ” Load API Key from .env
9
+ load_dotenv()
10
+ api_key = os.getenv("OPENAI_API_KEY")
11
+ client = OpenAI(api_key=api_key)
12
+
13
+
14
+ def extract_keywords(paragraph):
15
+ prompt = f"""
16
+ You are an expert in experiential event planning.
17
+
18
+ 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.
19
+
20
+ Each keyword should be 2-4 words long and describe a concrete idea or theme (e.g., "Photo booths", "smart vending", "interactive storytelling").
21
+
22
+ Event Description:
23
+ "{paragraph}"
24
+
25
+ Return the keywords as a comma-separated list.
26
+ """
27
+ response = client.chat.completions.create(
28
+ model="gpt-4",
29
+ messages=[{"role": "user", "content": prompt}],
30
+ temperature=0.7,
31
+ max_tokens=200
32
+ )
33
+
34
+ keywords_raw = response.choices[0].message.content
35
+ keywords = re.split(r'[,\n]', keywords_raw)
36
+ return [kw.strip().lower() for kw in keywords if kw.strip()]
37
+
38
+
39
+ def extract_keywords_from_title_and_link(title, link):
40
+ prompt = f"""
41
+ You are an expert in event innovation.
42
+
43
+ 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.
44
+
45
+ Title: {title}
46
+ Link: {link}
47
+
48
+ Return the keywords as a comma-separated list.
49
+ """
50
+ response = client.chat.completions.create(
51
+ model="gpt-4",
52
+ messages=[{"role": "user", "content": prompt}],
53
+ temperature=0.6,
54
+ max_tokens=150
55
+ )
56
+
57
+ raw = response.choices[0].message.content
58
+ return [kw.strip().lower() for kw in re.split(r'[,\n]', raw) if kw.strip()]
59
+
60
+
61
+ def search_similar_events_and_products_openai(keywords):
62
+ input_text = f"Generate 10 useful URLs for experiential event ideas or iBoothMe.com inspiration related to the keywords: {', '.join(keywords)}"
63
+
64
+ try:
65
+ print("🌐 Using OpenAI web search tool...")
66
+ response = client.responses.create(
67
+ model="gpt-4.1",
68
+ tools=[{"type": "web_search_preview"}],
69
+ input=input_text
70
+ )
71
+ content = response.output_text
72
+ results = []
73
+ for line in content.strip().split("\n"):
74
+ if "http" in line:
75
+ parts = line.split(" - ", 1)
76
+ if len(parts) == 2:
77
+ results.append((parts[0].strip(), parts[1].strip()))
78
+ else:
79
+ url = line.strip()
80
+ results.append((url, url))
81
+ return results[:10]
82
+ except Exception as e:
83
+ print(f"Search failed: {e}")
84
+ return []
85
+
86
+
87
+ def generate_event_ideas(paragraph, search_links, all_keywords, idea_count):
88
+ search_summary = "\n".join([f"- {title}: {url}" for title, url in search_links])
89
+
90
+ include_games = "game" in " ".join(all_keywords)
91
+ if include_games:
92
+ if idea_count == 6:
93
+ game_instruction = "Include **only one** game-related idea (e.g. quiz game, vending challenge)."
94
+ else:
95
+ game_instruction = "Include **no more than two** game-related ideas."
96
+ else:
97
+ game_instruction = ""
98
+
99
+ prompt = f"""
100
+ 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.
101
+
102
+ Based on the event description below, generate {idea_count} **unique and diverse** iBoothMe-powered event ideas.
103
+
104
+ **Event Description:**
105
+ {paragraph}
106
+
107
+ **Inspiration from Related Ideas:**
108
+ {search_summary}
109
+
110
+ πŸ’‘ **Your Task:**
111
+ 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.
112
+
113
+ You can optionally include:
114
+ - Studio Ghibli-inspired visuals **(in just one idea)**
115
+ - Personalized giveaways (e.g., Labibu dolls, custom t-shirts, stickers)
116
+ - Audio booths, video diaries, face filters, sound remixes, or creative vending
117
+
118
+ {game_instruction}
119
+
120
+ ❗ Important:
121
+ - Avoid using AR, VR, holograms, or projection domes
122
+ - Don’t repeat formats like photo booths
123
+ - Every idea should have a **creative title**
124
+ - Each idea should be described in a paragraph
125
+ - 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.
126
+
127
+ Return only the final ideas in markdown format.
128
+ """
129
+ response = client.chat.completions.create(
130
+ model="gpt-4",
131
+ messages=[{"role": "user", "content": prompt}],
132
+ temperature=0.95,
133
+ max_tokens=1500
134
+ )
135
+
136
+ return response.choices[0].message.content
137
+
138
+
139
+ def main_workflow(paragraph):
140
+ print("πŸš€ Started workflow")
141
+
142
+ if not paragraph.strip():
143
+ return "❌ Please enter an event description."
144
+
145
+ print("πŸ” Extracting keywords from paragraph...")
146
+ base_keywords = extract_keywords(paragraph)
147
+
148
+ print("🌐 Searching using OpenAI tool...")
149
+ links = search_similar_events_and_products_openai(base_keywords)
150
+
151
+ print("πŸ” Extracting extra keywords from titles and links...")
152
+ link_keywords = []
153
+ for title, url in links:
154
+ link_keywords.extend(extract_keywords_from_title_and_link(title, url))
155
+
156
+ all_keywords = sorted(set(base_keywords + link_keywords))
157
+
158
+ idea_count = random.choice([6, 7]) # randomly pick 6 or 7
159
+ print(f"🧠 Generating {idea_count} ideas...")
160
+ ideas = generate_event_ideas(paragraph, links, all_keywords, idea_count)
161
+
162
+ keyword_summaries = []
163
+ for kw in all_keywords[:10]:
164
+ try:
165
+ response = client.chat.completions.create(
166
+ model="gpt-4",
167
+ messages=[{"role": "user", "content": f"Give a short one-line event idea description using the keyword: {kw}"}],
168
+ temperature=0.6,
169
+ max_tokens=60
170
+ )
171
+ description = response.choices[0].message.content.strip()
172
+ keyword_summaries.append(f"- **{kw.title()}**: {description}")
173
+ except:
174
+ keyword_summaries.append(f"- **{kw.title()}**")
175
+
176
+ formatted_links = "\n".join(keyword_summaries)
177
+
178
+ return f"""
179
+ 🌐 **Relevant Ideas:**
180
+ {formatted_links}
181
+
182
+ {ideas}
183
+ """
184
+
185
+
186
+ # 🎨 Gradio UI
187
+ with gr.Blocks(title="iBoothMe Event Ideation App") as demo:
188
+ gr.Markdown("## πŸŽ‰ iBoothMe Event Idea Generator\nDescribe your event goal and receive interactive, tech-powered ideas!")
189
+
190
+ paragraph = gr.Textbox(label="πŸ“ Describe Your Event (e.g. Women's Day, Product Launch)", lines=4)
191
+
192
+ submit_btn = gr.Button("πŸš€ Generate Event Concepts")
193
+ output = gr.Markdown()
194
+
195
+ submit_btn.click(
196
+ fn=main_workflow,
197
+ inputs=[paragraph],
198
+ outputs=output,
199
+ show_progress=True
200
+ )
201
+
202
+ demo.launch(inline=False, share=True)