Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,8 +25,8 @@ def submit_boba_data(use_today, date, shop, drink, toppings, size, sugar, rating
|
|
25 |
return boba_data
|
26 |
|
27 |
def get_leaderboard():
|
28 |
-
leaderboard = boba_data.groupby('Shop').agg({'Rating': 'mean', 'Shop': 'count'}).sort_values(by='Rating', ascending=False)
|
29 |
-
return leaderboard
|
30 |
|
31 |
def get_statistics():
|
32 |
total_drinks = len(boba_data)
|
@@ -35,17 +35,35 @@ def get_statistics():
|
|
35 |
favorite_topping = boba_data['Toppings'].mode()[0]
|
36 |
average_sugar = boba_data['Sugar'].mean()
|
37 |
total_spent = boba_data['Price'].sum()
|
38 |
-
else:
|
39 |
-
favorite_drink = "No data"
|
40 |
-
favorite_topping = "No data"
|
41 |
-
average_sugar = "No data"
|
42 |
-
total_spent = 0
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
# Define Gradio inputs and interface
|
51 |
inputs = [
|
@@ -74,10 +92,17 @@ leaderboard_iface = gr.Interface(
|
|
74 |
title="Boba Leaderboard"
|
75 |
)
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
stats_iface = gr.Interface(
|
78 |
-
fn=
|
79 |
inputs=None,
|
80 |
-
outputs=
|
81 |
title="Boba Consumption Stats"
|
82 |
)
|
83 |
|
|
|
25 |
return boba_data
|
26 |
|
27 |
def get_leaderboard():
|
28 |
+
leaderboard = boba_data.groupby('Shop').agg({'Rating': 'mean', 'Shop': 'count'}).rename(columns={'Shop': 'Number of Entries'}).sort_values(by='Rating', ascending=False)
|
29 |
+
return leaderboard.reset_index()
|
30 |
|
31 |
def get_statistics():
|
32 |
total_drinks = len(boba_data)
|
|
|
35 |
favorite_topping = boba_data['Toppings'].mode()[0]
|
36 |
average_sugar = boba_data['Sugar'].mean()
|
37 |
total_spent = boba_data['Price'].sum()
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
# Plotting
|
40 |
+
fig, axs = plt.subplots(1, 2, figsize=(12, 5))
|
41 |
+
|
42 |
+
# Plot 1: Sugar Distribution
|
43 |
+
sns.histplot(boba_data['Sugar'], bins=10, kde=True, ax=axs[0])
|
44 |
+
axs[0].set_title('Sugar Distribution')
|
45 |
+
axs[0].set_xlabel('Sugar (%)')
|
46 |
+
axs[0].set_ylabel('Frequency')
|
47 |
+
|
48 |
+
# Plot 2: Rating Distribution
|
49 |
+
sns.histplot(boba_data['Rating'], bins=5, kde=True, ax=axs[1])
|
50 |
+
axs[1].set_title('Rating Distribution')
|
51 |
+
axs[1].set_xlabel('Rating')
|
52 |
+
axs[1].set_ylabel('Frequency')
|
53 |
+
|
54 |
+
# Save plots to BytesIO and convert to image
|
55 |
+
img = BytesIO()
|
56 |
+
plt.savefig(img, format='png')
|
57 |
+
plt.close(fig)
|
58 |
+
img.seek(0)
|
59 |
+
|
60 |
+
return (f"Total drinks: {total_drinks}\n"
|
61 |
+
f"Favorite drink: {favorite_drink}\n"
|
62 |
+
f"Favorite topping: {favorite_topping}\n"
|
63 |
+
f"Average sugar level: {average_sugar:.2f}%\n"
|
64 |
+
f"Total spent: ${total_spent:.2f}", img.getvalue())
|
65 |
+
else:
|
66 |
+
return "No data available", None
|
67 |
|
68 |
# Define Gradio inputs and interface
|
69 |
inputs = [
|
|
|
92 |
title="Boba Leaderboard"
|
93 |
)
|
94 |
|
95 |
+
def display_statistics():
|
96 |
+
stats_text, stats_img = get_statistics()
|
97 |
+
if stats_img:
|
98 |
+
return [stats_text, gr.Image(value=stats_img)]
|
99 |
+
else:
|
100 |
+
return stats_text
|
101 |
+
|
102 |
stats_iface = gr.Interface(
|
103 |
+
fn=display_statistics,
|
104 |
inputs=None,
|
105 |
+
outputs=[gr.Textbox(), gr.Image()],
|
106 |
title="Boba Consumption Stats"
|
107 |
)
|
108 |
|