Download app.py from zero1337/reunion: direct link, hf CLI and curl.
- Browser
- Download file 8.14 kB
-
https://huggingface.co/spaces/zero1337/reunion/resolve/main/app.py
- Command line
-
hf download hf://spaces/zero1337/reunion/app.py
-
curl -L -o app.py https://huggingface.co/spaces/zero1337/reunion/resolve/main/app.py
8.14 kB
| import gradio as gr | |
| import pandas as pd | |
| import plotly.express as px | |
| import plotly.graph_objects as go | |
| from datetime import datetime, timedelta | |
| import base64 | |
| import os | |
| import shutil | |
| # Simulated data | |
| family_members = ["Alice", "Bob", "Charlie", "Diana", "Eve"] | |
| locations = ["Beach House", "Mountain Cabin", "City Hotel", "Countryside Villa"] | |
| activities = ["Hiking", "Board Games", "Cooking Class", "Sightseeing"] | |
| chats = [] | |
| votes = {loc: 0 for loc in locations} | |
| activity_signups = {act: [] for act in activities} | |
| pooled_money = 0 | |
| expenses = [] | |
| itinerary = [] | |
| photos = [] | |
| # Create a directory to store uploaded photos | |
| if not os.path.exists("uploaded_photos"): | |
| os.makedirs("uploaded_photos") | |
| def login(username, password): | |
| if username in family_members and password == "password": | |
| return username | |
| return None | |
| def send_invite(member): | |
| return f"Invitation sent to {member}!" | |
| def vote_location(username, location): | |
| votes[location] += 1 | |
| df = pd.DataFrame(list(votes.items()), columns=['Location', 'Votes']) | |
| fig = px.bar(df, x='Location', y='Votes', title='Location Votes') | |
| return f"Vote recorded for {location} by {username}.", fig | |
| def sign_up_activity(username, activity): | |
| if username not in activity_signups[activity]: | |
| activity_signups[activity].append(username) | |
| df = pd.DataFrame([(act, len(signups)) for act, signups in activity_signups.items()], | |
| columns=['Activity', 'Signups']) | |
| fig = px.bar(df, x='Activity', y='Signups', title='Activity Signups') | |
| return f"{username} signed up for {activity}.", fig | |
| def add_chat_message(username, message): | |
| chats.append(f"{username}: {message}") | |
| return "\n".join(chats) | |
| def pool_money(username, amount): | |
| global pooled_money | |
| pooled_money += amount | |
| df = pd.DataFrame([('Pooled', pooled_money), ('Target', 1000)], columns=['Type', 'Amount']) | |
| fig = px.pie(df, values='Amount', names='Type', title='Money Pool Progress') | |
| return f"${amount} added to the pool by {username}. Total pooled: ${pooled_money}", fig | |
| def add_expense(username, description, amount): | |
| expenses.append({"user": username, "description": description, "amount": amount}) | |
| df = pd.DataFrame(expenses) | |
| fig = px.bar(df, x='description', y='amount', color='user', title='Expenses Breakdown') | |
| return "Expense added successfully", fig | |
| def add_itinerary_item(date, time, activity): | |
| try: | |
| # Attempt to parse the date and time | |
| datetime.strptime(date, "%Y-%m-%d") | |
| datetime.strptime(time, "%H:%M") | |
| except ValueError: | |
| return "Invalid date or time format. Please use YYYY-MM-DD for date and HH:MM for time.", None | |
| itinerary.append({"date": date, "time": time, "activity": activity}) | |
| itinerary.sort(key=lambda x: (x['date'], x['time'])) | |
| df = pd.DataFrame(itinerary) | |
| fig = go.Figure(data=[go.Table( | |
| header=dict(values=['Date', 'Time', 'Activity']), | |
| cells=dict(values=[df.date, df.time, df.activity]) | |
| )]) | |
| fig.update_layout(title='Itinerary') | |
| return "Itinerary item added successfully", fig | |
| def upload_photo(username, photo): | |
| if photo is not None: | |
| # Generate a unique filename | |
| filename = f"{username}_{datetime.now().strftime('%Y%m%d_%H%M%S')}{os.path.splitext(photo.name)[1]}" | |
| file_path = os.path.join("uploaded_photos", filename) | |
| # Copy the uploaded file to our directory | |
| shutil.copy(photo.name, file_path) | |
| # Add the file path to our photos list | |
| photos.append({"user": username, "photo": file_path}) | |
| # Return all photo paths for the gallery | |
| photo_paths = [p["photo"] for p in photos] | |
| return f"Photo uploaded by {username}", gr.Gallery(value=photo_paths) | |
| return "No photo uploaded", None | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Family Reunion Planner") | |
| username = gr.State(None) | |
| with gr.Row(): | |
| login_username = gr.Textbox(label="Username") | |
| login_password = gr.Textbox(label="Password", type="password") | |
| login_button = gr.Button("Login") | |
| with gr.Column(visible=False) as main_interface: | |
| gr.Markdown("## Welcome to the Family Reunion Planner!") | |
| with gr.Tab("Invitations"): | |
| member_dropdown = gr.Dropdown(choices=family_members, label="Select Family Member") | |
| invite_button = gr.Button("Send Invite") | |
| invite_output = gr.Textbox(label="Invitation Status") | |
| with gr.Tab("Location Voting"): | |
| location_dropdown = gr.Dropdown(choices=locations, label="Select Location") | |
| vote_button = gr.Button("Vote") | |
| vote_output = gr.Textbox(label="Voting Results") | |
| vote_chart = gr.Plot(label="Voting Chart") | |
| with gr.Tab("Activity Signup"): | |
| activity_dropdown = gr.Dropdown(choices=activities, label="Select Activity") | |
| signup_button = gr.Button("Sign Up") | |
| signup_output = gr.Textbox(label="Signup Status") | |
| signup_chart = gr.Plot(label="Signup Chart") | |
| with gr.Tab("Chat Forum"): | |
| chat_input = gr.Textbox(label="Type your message") | |
| chat_button = gr.Button("Send") | |
| chat_output = gr.Textbox(label="Chat History") | |
| with gr.Tab("Money Pool"): | |
| money_input = gr.Number(label="Amount to Add ($)") | |
| pool_button = gr.Button("Add to Pool") | |
| pool_output = gr.Textbox(label="Pool Status") | |
| pool_chart = gr.Plot(label="Pool Progress") | |
| with gr.Tab("Expense Tracking"): | |
| expense_description = gr.Textbox(label="Expense Description") | |
| expense_amount = gr.Number(label="Expense Amount ($)") | |
| expense_button = gr.Button("Add Expense") | |
| expense_output = gr.Textbox(label="Expense Status") | |
| expense_chart = gr.Plot(label="Expenses Chart") | |
| with gr.Tab("Itinerary Planning"): | |
| itinerary_date = gr.Textbox(label="Date (YYYY-MM-DD)") | |
| itinerary_time = gr.Textbox(label="Time (HH:MM)") | |
| itinerary_activity = gr.Textbox(label="Activity Description") | |
| itinerary_button = gr.Button("Add to Itinerary") | |
| itinerary_output = gr.Textbox(label="Itinerary Status") | |
| itinerary_chart = gr.Plot(label="Itinerary") | |
| with gr.Tab("Photo Sharing"): | |
| photo_upload = gr.File(label="Upload Photo") | |
| photo_button = gr.Button("Share Photo") | |
| photo_output = gr.Textbox(label="Upload Status") | |
| photo_gallery = gr.Gallery(label="Shared Photos") | |
| def on_login(login_username, login_password): | |
| user = login(login_username, login_password) | |
| if user: | |
| # When logging in, update the gallery with all existing photos | |
| photo_paths = [p["photo"] for p in photos] | |
| return gr.update(visible=True), user, gr.Gallery(value=photo_paths) | |
| else: | |
| return gr.update(visible=False), None, None | |
| login_button.click( | |
| on_login, | |
| inputs=[login_username, login_password], | |
| outputs=[main_interface, username, photo_gallery] | |
| ) | |
| invite_button.click(send_invite, inputs=member_dropdown, outputs=invite_output) | |
| vote_button.click(vote_location, inputs=[username, location_dropdown], outputs=[vote_output, vote_chart]) | |
| signup_button.click(sign_up_activity, inputs=[username, activity_dropdown], outputs=[signup_output, signup_chart]) | |
| chat_button.click(add_chat_message, inputs=[username, chat_input], outputs=chat_output) | |
| pool_button.click(pool_money, inputs=[username, money_input], outputs=[pool_output, pool_chart]) | |
| expense_button.click(add_expense, inputs=[username, expense_description, expense_amount], outputs=[expense_output, expense_chart]) | |
| itinerary_button.click(add_itinerary_item, inputs=[itinerary_date, itinerary_time, itinerary_activity], outputs=[itinerary_output, itinerary_chart]) | |
| photo_button.click(upload_photo, inputs=[username, photo_upload], outputs=[photo_output, photo_gallery]) | |
| demo.launch() | |