hlydecker commited on
Commit
899f23c
1 Parent(s): 88164e2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+
4
+ # Placeholder for boba data
5
+ boba_data = pd.DataFrame(columns=["Date", "Shop", "Drink", "Toppings", "Size", "Rating", "Price"])
6
+
7
+ def submit_boba_data(date, shop, drink, toppings, size, rating, price):
8
+ global boba_data
9
+ new_entry = {"Date": date, "Shop": shop, "Drink": drink, "Toppings": toppings, "Size": size, "Rating": rating, "Price": price}
10
+ boba_data = boba_data.append(new_entry, ignore_index=True)
11
+ return boba_data
12
+
13
+ def get_leaderboard():
14
+ leaderboard = boba_data.groupby('Shop').agg({'Rating': 'mean', 'Shop': 'count'}).sort_values(by='Rating', ascending=False)
15
+ return leaderboard
16
+
17
+ def get_statistics():
18
+ total_drinks = len(boba_data)
19
+ favorite_drink = boba_data['Drink'].mode()[0] if total_drinks > 0 else "No data"
20
+ total_spent = boba_data['Price'].sum()
21
+ return f"Total drinks: {total_drinks}\nFavorite drink: {favorite_drink}\nTotal spent: ${total_spent}"
22
+
23
+ # Define Gradio inputs and interface
24
+ inputs = [
25
+ gr.inputs.Textbox(label="Date"),
26
+ gr.inputs.Textbox(label="Shop"),
27
+ gr.inputs.Textbox(label="Drink"),
28
+ gr.inputs.Textbox(label="Toppings"),
29
+ gr.inputs.Dropdown(["Small", "Medium", "Large"], label="Size"),
30
+ gr.inputs.Slider(1, 5, label="Rating"),
31
+ gr.inputs.Number(label="Price")
32
+ ]
33
+
34
+ iface = gr.Interface(
35
+ fn=submit_boba_data,
36
+ inputs=inputs,
37
+ outputs=gr.DataFrame(),
38
+ title="Boba Tracker Data Entry"
39
+ )
40
+
41
+ leaderboard_iface = gr.Interface(
42
+ fn=get_leaderboard,
43
+ inputs=None,
44
+ outputs=gr.DataFrame(),
45
+ title="Boba Leaderboard"
46
+ )
47
+
48
+ stats_iface = gr.Interface(
49
+ fn=get_statistics,
50
+ inputs=None,
51
+ outputs="text",
52
+ title="Boba Consumption Stats"
53
+ )
54
+
55
+ # Combine all interfaces into one app
56
+ gr.TabbedInterface([iface, leaderboard_iface, stats_iface], ["Data Entry", "Leaderboard", "Statistics"]).launch()