Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,39 @@
|
|
1 |
-
import torch
|
2 |
import gradio as gr
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
|
5 |
+
# Sample population data (you can use a CSV instead)
|
6 |
+
data = {
|
7 |
+
"Country": ["India", "China", "USA", "Indonesia", "Brazil"],
|
8 |
+
"Population": [1400000000, 1410000000, 331000000, 273000000, 213000000]
|
9 |
+
}
|
10 |
+
df = pd.DataFrame(data)
|
11 |
+
|
12 |
+
def plot_chart(countries, chart_type):
|
13 |
+
filtered_df = df[df["Country"].isin(countries)]
|
14 |
+
plt.figure(figsize=(8, 5))
|
15 |
+
|
16 |
+
if chart_type == "Bar":
|
17 |
+
plt.bar(filtered_df["Country"], filtered_df["Population"], color="skyblue")
|
18 |
+
plt.ylabel("Population")
|
19 |
+
else: # Pie chart
|
20 |
+
plt.pie(filtered_df["Population"], labels=filtered_df["Country"], autopct="%1.1f%%")
|
21 |
+
|
22 |
+
plt.title("Population by Country")
|
23 |
+
plt.tight_layout()
|
24 |
+
return plt
|
25 |
+
|
26 |
+
country_choices = df["Country"].tolist()
|
27 |
+
|
28 |
+
with gr.Blocks() as demo:
|
29 |
+
gr.Markdown("## 🌍 World Population Chart")
|
30 |
+
with gr.Row():
|
31 |
+
country_select = gr.CheckboxGroup(label="Select Countries", choices=country_choices, value=["India", "China"])
|
32 |
+
chart_type = gr.Radio(label="Chart Type", choices=["Bar", "Pie"], value="Bar")
|
33 |
+
output = gr.Plot()
|
34 |
+
|
35 |
+
country_select.change(plot_chart, inputs=[country_select, chart_type], outputs=output)
|
36 |
+
chart_type.change(plot_chart, inputs=[country_select, chart_type], outputs=output)
|
37 |
+
|
38 |
+
demo.launch()
|
39 |
+
|