|
|
import streamlit as st |
|
|
import requests |
|
|
import pandas as pd |
|
|
|
|
|
|
|
|
|
|
|
if st.experimental_get_query_params().get("page", [""])[0] == "docs": |
|
|
st.error("Page not found. Redirecting to the main dashboard...") |
|
|
st.experimental_set_query_params(page="") |
|
|
st.experimental_rerun() |
|
|
|
|
|
|
|
|
API_URL = "https://logeswari-backapp.hf.space" |
|
|
|
|
|
|
|
|
st.title("⭐World Population Dashboard") |
|
|
|
|
|
|
|
|
st.sidebar.header("Filter") |
|
|
selected_continent = st.sidebar.selectbox( |
|
|
"Select the Continent:", |
|
|
['Asia', 'Africa', 'North America', 'South America', 'Europe', 'Oceania'] |
|
|
) |
|
|
|
|
|
|
|
|
if st.sidebar.button("Get Data"): |
|
|
|
|
|
response = requests.get(f"{API_URL}/continent/{selected_continent}") |
|
|
|
|
|
if response.status_code == 200: |
|
|
data = response.json() |
|
|
st.write(data) |
|
|
|
|
|
|
|
|
st.header(f"Data of {data['continent']}") |
|
|
st.metric("Total Population", f"{data['total_population']:,}") |
|
|
st.metric("Total Area (sq km)", f"{data['total_area']:,}") |
|
|
st.metric("Population Density", f"{data['continent_population_density']:.2f}") |
|
|
st.subheader("Population Highlights") |
|
|
st.write( |
|
|
f"Max Population :{data['max_population']['country']} " |
|
|
f"({data['max_population']['population']:,})" |
|
|
) |
|
|
|
|
|
st.write( |
|
|
f"Min Population:{data['min_population']['country']} " |
|
|
f"({data['min_population']['population']:,})" |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
|
st.error(f"Error: {response.json()['detail']}") |
|
|
|
|
|
|
|
|
|