Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -35,35 +35,18 @@ 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 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
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,19 +75,12 @@ leaderboard_iface = gr.Interface(
|
|
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=
|
104 |
inputs=None,
|
105 |
-
outputs=
|
106 |
title="Boba Consumption Stats"
|
107 |
)
|
108 |
|
109 |
# Combine all interfaces into one app
|
110 |
-
gr.TabbedInterface([iface, leaderboard_iface, stats_iface], ["Data Entry", "Leaderboard", "Statistics"]).launch()
|
|
|
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 |
+
return (f"Total drinks: {total_drinks}\n"
|
45 |
+
f"Favorite drink: {favorite_drink}\n"
|
46 |
+
f"Favorite topping: {favorite_topping}\n"
|
47 |
+
f"Average sugar level: {average_sugar:.2f}%\n"
|
48 |
+
f"Total spent: ${total_spent:.2f}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
# Define Gradio inputs and interface
|
52 |
inputs = [
|
|
|
75 |
title="Boba Leaderboard"
|
76 |
)
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
stats_iface = gr.Interface(
|
79 |
+
fn=get_statistics,
|
80 |
inputs=None,
|
81 |
+
outputs="text",
|
82 |
title="Boba Consumption Stats"
|
83 |
)
|
84 |
|
85 |
# Combine all interfaces into one app
|
86 |
+
gr.TabbedInterface([iface, leaderboard_iface, stats_iface], ["Data Entry", "Leaderboard", "Statistics"]).launch()
|