🎉 Party Planner - Guest Table Arranger
Upload your guest list CSV and let AI arrange them into optimal circular table seating!
import gradio as gr import csv import io import json from typing import List, Dict, Any import math def parse_csv_file(file_content: str) -> Dict[str, Any]: """Parse CSV content and extract guest information from name and message columns""" try: # Create a StringIO object to read the CSV csv_file = io.StringIO(file_content) # Read CSV with different possible delimiters for delimiter in [',', ';', '\t']: try: csv_file.seek(0) # Reset file pointer reader = csv.DictReader(csv_file, delimiter=delimiter) # Get the header row headers = reader.fieldnames if not headers or len(headers) < 2: continue # Use the first two columns: name and message name_column = headers[0] message_column = headers[1] # Parse the data and filter out entries with blank names or descriptions guests = [] for i, row in enumerate(reader): name = row.get(name_column, '').strip() title = row.get(message_column, '').strip() # Only add if both name and description are not blank if name and title: guests.append({ 'id': i, 'name': name, 'title': title }) if guests: return {'success': True, 'guests': guests, 'total': len(guests)} except Exception as e: continue return {'success': False, 'error': 'Could not parse CSV file. Please ensure it has at least 2 columns (name and message).'} except Exception as e: return {'success': False, 'error': f'Error parsing CSV: {str(e)}'} def arrange_guests_into_tables(guests: List[Dict]) -> List[List[Dict]]: """Arrange guests into tables of 10 people each with smart distribution""" if not guests: return [] # Categorize guests by industry/role type based on message content categories = { 'tech': ['engineer', 'developer', 'programmer', 'software', 'tech', 'it', 'data', 'ai', 'ml', 'technology', 'scientist'], 'business': ['manager', 'director', 'ceo', 'founder', 'executive', 'business', 'strategy', 'operations', 'consultant', 'product'], 'creative': ['designer', 'creative', 'marketing', 'content', 'writer', 'artist', 'media', 'communications', 'strategist'], 'sales': ['sales', 'account', 'client', 'business development', 'partnership', 'account manager'], 'finance': ['finance', 'accounting', 'investment', 'banking', 'financial', 'analyst', 'cfo'], 'other': [] } categorized_guests = {cat: [] for cat in categories.keys()} # Categorize each guest based on their message/description for guest in guests: title_lower = guest['title'].lower() categorized = False for category, keywords in categories.items(): if category == 'other': continue if any(keyword in title_lower for keyword in keywords): categorized_guests[category].append(guest) categorized = True break if not categorized: categorized_guests['other'].append(guest) # Calculate how many tables we need total_guests = len(guests) num_tables = (total_guests + 9) // 10 # Ceiling division to get number of tables needed # Initialize tables tables = [[] for _ in range(num_tables)] # Distribute guests strategically across all tables # First, distribute major categories evenly major_categories = ['tech', 'business', 'creative', 'sales'] for category in major_categories: guests_in_category = categorized_guests[category] if guests_in_category: # Distribute evenly across all tables for i, guest in enumerate(guests_in_category): table_index = i % num_tables if len(tables[table_index]) < 10: tables[table_index].append(guest) # Then distribute remaining guests (finance, other) remaining_guests = [] for category in ['finance', 'other']: remaining_guests.extend(categorized_guests[category]) # Also add any guests that didn't fit in the first round for table in tables: for guest in guests: if guest not in [g for table_guests in tables for g in table_guests]: if len(table) < 10: table.append(guest) break # Fill remaining slots with any leftover guests for guest in guests: if guest not in [g for table_guests in tables for g in table_guests]: for table in tables: if len(table) < 10: table.append(guest) break return tables def create_circular_table_html(table_number: int, guests: List[Dict]) -> str: """Create HTML for a circular table with guests seated around it""" if not guests: return "" # Calculate positions for seats around the circle num_guests = len(guests) radius = 120 # Radius of the circle center_x, center_y = 150, 150 # Center of the circle # Generate seat positions seats = [] for i in range(num_guests): angle = (2 * 3.14159 * i) / num_guests # Distribute evenly around circle x = center_x + radius * math.cos(angle) y = center_y + radius * math.sin(angle) seats.append((x, y)) # Create HTML for the table html = f"""
Total Guests: {total_guests} | Tables Created: {len(tables)}
Upload your guest list CSV and let AI arrange them into optimal circular table seating!
name,message John Smith,Software Engineer at TechCorp Sarah Johnson,Marketing Director at Creative Agency Michael Brown,CEO of StartupXYZ
🎉 Your tables will appear as beautiful circles with guests seated around them