url changed
Browse files
app.py
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# Set the FastAPI base URL
|
| 6 |
+
API_URL="https://tharu22-world-population.hf.space"
|
| 7 |
+
# Streamlit app title
|
| 8 |
+
st.title("World Population ")
|
| 9 |
+
|
| 10 |
+
# Load the data
|
| 11 |
+
file_path = "C:/Users/keerthi/Downloads/world_population.csv"
|
| 12 |
+
df = pd.read_csv(file_path)
|
| 13 |
+
|
| 14 |
+
# Streamlit app
|
| 15 |
+
def main():
|
| 16 |
+
st.title("World Population Explorer 🌍")
|
| 17 |
+
|
| 18 |
+
# Sidebar for continent selection
|
| 19 |
+
st.sidebar.header("Select a Continent")
|
| 20 |
+
continent_list = df['Continent'].unique().tolist()
|
| 21 |
+
selected_continent = st.sidebar.selectbox("Choose a continent", continent_list)
|
| 22 |
+
|
| 23 |
+
if selected_continent:
|
| 24 |
+
# Filter data for the selected continent
|
| 25 |
+
continent_data = df[df['Continent'] == selected_continent]
|
| 26 |
+
|
| 27 |
+
# Calculate statistics
|
| 28 |
+
max_population = continent_data['Population'].max()
|
| 29 |
+
min_population = continent_data['Population'].min()
|
| 30 |
+
max_country = continent_data.loc[continent_data['Population'].idxmax()]['Country']
|
| 31 |
+
min_country = continent_data.loc[continent_data['Population'].idxmin()]['Country']
|
| 32 |
+
average_population = continent_data['Population'].mean()
|
| 33 |
+
total_area = continent_data['Area'].sum()
|
| 34 |
+
total_population = continent_data['Population'].sum()
|
| 35 |
+
continent_density = total_population / total_area
|
| 36 |
+
|
| 37 |
+
# Display results
|
| 38 |
+
st.header(f"Statistics for {selected_continent}")
|
| 39 |
+
|
| 40 |
+
st.subheader("Maximum Population")
|
| 41 |
+
st.write(f"The maximum population in {selected_continent} is **{max_population}** in **{max_country}**.")
|
| 42 |
+
|
| 43 |
+
st.subheader("Minimum Population")
|
| 44 |
+
st.write(f"The minimum population in {selected_continent} is **{min_population}** in **{min_country}**.")
|
| 45 |
+
|
| 46 |
+
st.subheader("Average Population")
|
| 47 |
+
st.write(f"The average population in {selected_continent} is **{average_population:.2f}**.")
|
| 48 |
+
|
| 49 |
+
st.subheader("Total Area")
|
| 50 |
+
st.write(f"The total area of {selected_continent} is **{total_area}** square kilometers.")
|
| 51 |
+
|
| 52 |
+
st.subheader("Total Population")
|
| 53 |
+
st.write(f"The total population of {selected_continent} is **{total_population}**.")
|
| 54 |
+
|
| 55 |
+
st.subheader("Population Density")
|
| 56 |
+
st.write(f"The population density of {selected_continent} is **{continent_density:.2f}** people per square kilometer.")
|