boba-tracker / app.py
hlydecker's picture
Create app.py
899f23c verified
raw
history blame
1.84 kB
import gradio as gr
import pandas as pd
# Placeholder for boba data
boba_data = pd.DataFrame(columns=["Date", "Shop", "Drink", "Toppings", "Size", "Rating", "Price"])
def submit_boba_data(date, shop, drink, toppings, size, rating, price):
global boba_data
new_entry = {"Date": date, "Shop": shop, "Drink": drink, "Toppings": toppings, "Size": size, "Rating": rating, "Price": price}
boba_data = boba_data.append(new_entry, ignore_index=True)
return boba_data
def get_leaderboard():
leaderboard = boba_data.groupby('Shop').agg({'Rating': 'mean', 'Shop': 'count'}).sort_values(by='Rating', ascending=False)
return leaderboard
def get_statistics():
total_drinks = len(boba_data)
favorite_drink = boba_data['Drink'].mode()[0] if total_drinks > 0 else "No data"
total_spent = boba_data['Price'].sum()
return f"Total drinks: {total_drinks}\nFavorite drink: {favorite_drink}\nTotal spent: ${total_spent}"
# Define Gradio inputs and interface
inputs = [
gr.inputs.Textbox(label="Date"),
gr.inputs.Textbox(label="Shop"),
gr.inputs.Textbox(label="Drink"),
gr.inputs.Textbox(label="Toppings"),
gr.inputs.Dropdown(["Small", "Medium", "Large"], label="Size"),
gr.inputs.Slider(1, 5, label="Rating"),
gr.inputs.Number(label="Price")
]
iface = gr.Interface(
fn=submit_boba_data,
inputs=inputs,
outputs=gr.DataFrame(),
title="Boba Tracker Data Entry"
)
leaderboard_iface = gr.Interface(
fn=get_leaderboard,
inputs=None,
outputs=gr.DataFrame(),
title="Boba Leaderboard"
)
stats_iface = gr.Interface(
fn=get_statistics,
inputs=None,
outputs="text",
title="Boba Consumption Stats"
)
# Combine all interfaces into one app
gr.TabbedInterface([iface, leaderboard_iface, stats_iface], ["Data Entry", "Leaderboard", "Statistics"]).launch()