dpang commited on
Commit
919e0e5
Β·
verified Β·
1 Parent(s): 1492d7f

Upload app_gradio.py

Browse files
Files changed (1) hide show
  1. app_gradio.py +206 -23
app_gradio.py CHANGED
@@ -3,6 +3,7 @@ import csv
3
  import io
4
  import json
5
  from typing import List, Dict, Any
 
6
 
7
  def parse_csv_file(file_content: str) -> Dict[str, Any]:
8
  """Parse CSV content and extract guest information from name and message columns"""
@@ -126,6 +127,102 @@ def arrange_guests_into_tables(guests: List[Dict]) -> List[List[Dict]]:
126
 
127
  return tables
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  def process_csv_and_arrange_tables(csv_content: str) -> str:
130
  """Main function to process CSV and arrange tables"""
131
  try:
@@ -147,20 +244,80 @@ def process_csv_and_arrange_tables(csv_content: str) -> str:
147
  if not tables:
148
  return "❌ No tables could be created."
149
 
150
- # Generate output
151
  output = f"πŸŽ‰ Successfully processed {total_guests} guests!\n\n"
152
  output += f"πŸ“Š Created {len(tables)} table(s) with smart distribution:\n\n"
153
 
154
- for i, table in enumerate(tables, 1):
155
- output += f"🍽️ **Table {i}** ({len(table)} guests):\n"
156
- for j, guest in enumerate(table, 1):
157
- output += f" {j}. **{guest['name']}** - {guest['title']}\n"
158
- output += "\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
160
  # Add statistics
161
- output += "πŸ“ˆ **Table Statistics:**\n"
 
 
 
 
 
 
 
 
162
  for i, table in enumerate(tables, 1):
163
- output += f" Table {i}: {len(table)} guests\n"
 
 
 
 
 
 
 
 
 
 
164
 
165
  return output
166
 
@@ -179,7 +336,12 @@ Lisa Chen,UX Designer at Design Studio
179
  Robert Taylor,Sales Manager at SalesForce
180
  Amanda Rodriguez,Financial Analyst at Finance Corp
181
  James Lee,Content Strategist at Media Group
182
- Jennifer White,Business Development at Growth Co"""
 
 
 
 
 
183
  return sample_data
184
 
185
  # Create the Gradio interface
@@ -188,18 +350,31 @@ with gr.Blocks(
188
  theme=gr.themes.Soft(),
189
  css="""
190
  .gradio-container {
191
- max-width: 1200px !important;
192
  margin: 0 auto !important;
193
  }
194
  .main-header {
195
  text-align: center;
196
  margin-bottom: 2rem;
 
 
 
 
 
197
  }
198
  .sample-csv {
199
  background: #f0f8ff;
200
  padding: 1rem;
201
  border-radius: 8px;
202
  margin: 1rem 0;
 
 
 
 
 
 
 
 
203
  }
204
  """
205
  ) as demo:
@@ -207,26 +382,28 @@ with gr.Blocks(
207
  gr.HTML("""
208
  <div class="main-header">
209
  <h1>πŸŽ‰ Party Planner - Guest Table Arranger</h1>
210
- <p>Upload your guest list CSV and let AI arrange them into optimal table seating!</p>
211
  </div>
212
  """)
213
 
214
  with gr.Row():
215
  with gr.Column(scale=1):
216
  gr.HTML("""
217
- <h3>πŸ“‹ How to use:</h3>
218
- <ol>
219
- <li>Prepare a CSV file with 2 columns: <strong>name</strong> and <strong>message/description</strong></li>
220
- <li>Upload your CSV file below</li>
221
- <li>Click "Arrange Tables" to see the smart seating arrangement</li>
222
- </ol>
223
-
224
- <div class="sample-csv">
225
- <h4>πŸ“„ Sample CSV Format:</h4>
226
- <pre>name,message
 
227
  John Smith,Software Engineer at TechCorp
228
  Sarah Johnson,Marketing Director at Creative Agency
229
  Michael Brown,CEO of StartupXYZ</pre>
 
230
  </div>
231
  """)
232
 
@@ -240,6 +417,12 @@ Michael Brown,CEO of StartupXYZ</pre>
240
  download_sample = gr.Button("πŸ“₯ Download Sample CSV", variant="secondary")
241
 
242
  with gr.Column(scale=2):
 
 
 
 
 
 
243
  csv_input = gr.Textbox(
244
  label="πŸ“ Paste your CSV content here (or upload file below)",
245
  placeholder="Paste your CSV content here...",
@@ -254,9 +437,9 @@ Michael Brown,CEO of StartupXYZ</pre>
254
 
255
  arrange_btn = gr.Button("🎯 Arrange Tables", variant="primary", size="lg")
256
 
257
- output = gr.Markdown(
258
  label="πŸ“Š Table Arrangement Results",
259
- value="Upload your guest list to see the table arrangement!"
260
  )
261
 
262
  # Event handlers
 
3
  import io
4
  import json
5
  from typing import List, Dict, Any
6
+ import math
7
 
8
  def parse_csv_file(file_content: str) -> Dict[str, Any]:
9
  """Parse CSV content and extract guest information from name and message columns"""
 
127
 
128
  return tables
129
 
130
+ def create_circular_table_html(table_number: int, guests: List[Dict]) -> str:
131
+ """Create HTML for a circular table with guests seated around it"""
132
+ if not guests:
133
+ return ""
134
+
135
+ # Calculate positions for seats around the circle
136
+ num_guests = len(guests)
137
+ radius = 120 # Radius of the circle
138
+ center_x, center_y = 150, 150 # Center of the circle
139
+
140
+ # Generate seat positions
141
+ seats = []
142
+ for i in range(num_guests):
143
+ angle = (2 * 3.14159 * i) / num_guests # Distribute evenly around circle
144
+ x = center_x + radius * math.cos(angle)
145
+ y = center_y + radius * math.sin(angle)
146
+ seats.append((x, y))
147
+
148
+ # Create HTML for the table
149
+ html = f"""
150
+ <div class="table-container" style="margin: 20px; display: inline-block; text-align: center;">
151
+ <div class="table-circle" style="
152
+ width: 300px;
153
+ height: 300px;
154
+ position: relative;
155
+ margin: 0 auto;
156
+ ">
157
+ <!-- Table circle -->
158
+ <div style="
159
+ position: absolute;
160
+ top: 50%;
161
+ left: 50%;
162
+ transform: translate(-50%, -50%);
163
+ width: 240px;
164
+ height: 240px;
165
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
166
+ border-radius: 50%;
167
+ border: 4px solid #4a5568;
168
+ display: flex;
169
+ align-items: center;
170
+ justify-content: center;
171
+ color: white;
172
+ font-weight: bold;
173
+ font-size: 18px;
174
+ box-shadow: 0 4px 8px rgba(0,0,0,0.3);
175
+ ">
176
+ Table {table_number}
177
+ </div>
178
+ """
179
+
180
+ # Add seats around the table
181
+ for i, (guest, (x, y)) in enumerate(zip(guests, seats)):
182
+ # Get initials from name
183
+ initials = ''.join([name[0].upper() for name in guest['name'].split() if name])
184
+ if not initials:
185
+ initials = guest['name'][:2].upper()
186
+
187
+ html += f"""
188
+ <div class="seat" style="
189
+ position: absolute;
190
+ left: {x}px;
191
+ top: {y}px;
192
+ transform: translate(-50%, -50%);
193
+ width: 40px;
194
+ height: 40px;
195
+ background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
196
+ border-radius: 50%;
197
+ border: 2px solid #2f855a;
198
+ display: flex;
199
+ align-items: center;
200
+ justify-content: center;
201
+ color: white;
202
+ font-weight: bold;
203
+ font-size: 12px;
204
+ cursor: pointer;
205
+ box-shadow: 0 2px 4px rgba(0,0,0,0.2);
206
+ transition: all 0.3s ease;
207
+ "
208
+ title="{guest['name']} - {guest['title']}"
209
+ onmouseover="this.style.transform='translate(-50%, -50%) scale(1.1)'; this.style.boxShadow='0 4px 8px rgba(0,0,0,0.4)';"
210
+ onmouseout="this.style.transform='translate(-50%, -50%) scale(1)'; this.style.boxShadow='0 2px 4px rgba(0,0,0,0.2)';"
211
+ >
212
+ {initials}
213
+ </div>
214
+ """
215
+
216
+ html += """
217
+ </div>
218
+ <div style="margin-top: 10px; font-weight: bold; color: #4a5568;">
219
+ {len(guests)} guests
220
+ </div>
221
+ </div>
222
+ """
223
+
224
+ return html
225
+
226
  def process_csv_and_arrange_tables(csv_content: str) -> str:
227
  """Main function to process CSV and arrange tables"""
228
  try:
 
244
  if not tables:
245
  return "❌ No tables could be created."
246
 
247
+ # Generate output with circular tables
248
  output = f"πŸŽ‰ Successfully processed {total_guests} guests!\n\n"
249
  output += f"πŸ“Š Created {len(tables)} table(s) with smart distribution:\n\n"
250
 
251
+ # Add CSS for styling
252
+ output += """
253
+ <style>
254
+ .tables-container {
255
+ display: flex;
256
+ flex-wrap: wrap;
257
+ justify-content: center;
258
+ gap: 20px;
259
+ margin: 20px 0;
260
+ }
261
+ .table-container {
262
+ background: white;
263
+ border-radius: 15px;
264
+ padding: 20px;
265
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
266
+ border: 1px solid #e2e8f0;
267
+ }
268
+ .guest-list {
269
+ margin-top: 20px;
270
+ text-align: left;
271
+ max-width: 800px;
272
+ margin-left: auto;
273
+ margin-right: auto;
274
+ }
275
+ .guest-list h3 {
276
+ color: #4a5568;
277
+ border-bottom: 2px solid #e2e8f0;
278
+ padding-bottom: 10px;
279
+ margin-bottom: 15px;
280
+ }
281
+ .guest-item {
282
+ background: #f7fafc;
283
+ padding: 8px 12px;
284
+ margin: 5px 0;
285
+ border-radius: 6px;
286
+ border-left: 4px solid #667eea;
287
+ }
288
+ .stats {
289
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
290
+ color: white;
291
+ padding: 15px;
292
+ border-radius: 10px;
293
+ margin: 20px 0;
294
+ text-align: center;
295
+ }
296
+ </style>
297
+ """
298
 
299
  # Add statistics
300
+ output += f"""
301
+ <div class="stats">
302
+ <h3>πŸ“ˆ Table Statistics</h3>
303
+ <p>Total Guests: {total_guests} | Tables Created: {len(tables)}</p>
304
+ </div>
305
+ """
306
+
307
+ # Create circular tables
308
+ output += '<div class="tables-container">'
309
  for i, table in enumerate(tables, 1):
310
+ output += create_circular_table_html(i, table)
311
+ output += '</div>'
312
+
313
+ # Add detailed guest list
314
+ output += '<div class="guest-list">'
315
+ for i, table in enumerate(tables, 1):
316
+ output += f'<h3>🍽️ Table {i} ({len(table)} guests)</h3>'
317
+ for j, guest in enumerate(table, 1):
318
+ output += f'<div class="guest-item">{j}. <strong>{guest["name"]}</strong> - {guest["title"]}</div>'
319
+ output += '<br>'
320
+ output += '</div>'
321
 
322
  return output
323
 
 
336
  Robert Taylor,Sales Manager at SalesForce
337
  Amanda Rodriguez,Financial Analyst at Finance Corp
338
  James Lee,Content Strategist at Media Group
339
+ Jennifer White,Business Development at Growth Co
340
+ Alex Thompson,Data Engineer at DataFlow
341
+ Maria Garcia,Creative Director at ArtStudio
342
+ Chris Anderson,VP of Sales at SalesPro
343
+ Rachel Kim,Product Designer at DesignHub
344
+ Tom Wilson,Investment Analyst at Capital Corp"""
345
  return sample_data
346
 
347
  # Create the Gradio interface
 
350
  theme=gr.themes.Soft(),
351
  css="""
352
  .gradio-container {
353
+ max-width: 1400px !important;
354
  margin: 0 auto !important;
355
  }
356
  .main-header {
357
  text-align: center;
358
  margin-bottom: 2rem;
359
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
360
+ color: white;
361
+ padding: 2rem;
362
+ border-radius: 15px;
363
+ margin-bottom: 2rem;
364
  }
365
  .sample-csv {
366
  background: #f0f8ff;
367
  padding: 1rem;
368
  border-radius: 8px;
369
  margin: 1rem 0;
370
+ border-left: 4px solid #667eea;
371
+ }
372
+ .input-section {
373
+ background: white;
374
+ padding: 20px;
375
+ border-radius: 10px;
376
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
377
+ margin-bottom: 20px;
378
  }
379
  """
380
  ) as demo:
 
382
  gr.HTML("""
383
  <div class="main-header">
384
  <h1>πŸŽ‰ Party Planner - Guest Table Arranger</h1>
385
+ <p>Upload your guest list CSV and let AI arrange them into optimal circular table seating!</p>
386
  </div>
387
  """)
388
 
389
  with gr.Row():
390
  with gr.Column(scale=1):
391
  gr.HTML("""
392
+ <div class="input-section">
393
+ <h3>πŸ“‹ How to use:</h3>
394
+ <ol>
395
+ <li>Prepare a CSV file with 2 columns: <strong>name</strong> and <strong>message/description</strong></li>
396
+ <li>Upload your CSV file below</li>
397
+ <li>Click "Arrange Tables" to see the smart circular seating arrangement</li>
398
+ </ol>
399
+
400
+ <div class="sample-csv">
401
+ <h4>πŸ“„ Sample CSV Format:</h4>
402
+ <pre>name,message
403
  John Smith,Software Engineer at TechCorp
404
  Sarah Johnson,Marketing Director at Creative Agency
405
  Michael Brown,CEO of StartupXYZ</pre>
406
+ </div>
407
  </div>
408
  """)
409
 
 
417
  download_sample = gr.Button("πŸ“₯ Download Sample CSV", variant="secondary")
418
 
419
  with gr.Column(scale=2):
420
+ gr.HTML("""
421
+ <div class="input-section">
422
+ <h3>πŸ“ Upload Your Guest List</h3>
423
+ </div>
424
+ """)
425
+
426
  csv_input = gr.Textbox(
427
  label="πŸ“ Paste your CSV content here (or upload file below)",
428
  placeholder="Paste your CSV content here...",
 
437
 
438
  arrange_btn = gr.Button("🎯 Arrange Tables", variant="primary", size="lg")
439
 
440
+ output = gr.HTML(
441
  label="πŸ“Š Table Arrangement Results",
442
+ value="<div style='text-align: center; padding: 40px; color: #666;'><h3>Upload your guest list to see the circular table arrangement!</h3><p>πŸŽ‰ Your tables will appear as beautiful circles with guests seated around them</p></div>"
443
  )
444
 
445
  # Event handlers