afia1naseem2 commited on
Commit
254a2b7
Β·
verified Β·
1 Parent(s): aef5261

Upload app.py

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