File size: 1,984 Bytes
ee3cf7e
 
 
 
b0aa141
 
 
 
 
 
 
ee3cf7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d67a15d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import streamlit as st
import requests
import pandas as pd


# Redirect /docs to the main page
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()
    
# Set the FastAPI base URL
API_URL = "https://logeswari-backapp.hf.space"

# Streamlit app title
st.title("⭐World Population Dashboard")

# Sidebar filter for continents
st.sidebar.header("Filter")
selected_continent = st.sidebar.selectbox(
    "Select the Continent:",
    ['Asia', 'Africa', 'North America', 'South America', 'Europe', 'Oceania']
)

# Fetch data from the FastAPI endpoint
if st.sidebar.button("Get Data"):
    # Call FastAPI to get continent data
    response = requests.get(f"{API_URL}/continent/{selected_continent}")
    
    if response.status_code == 200:
        data = response.json()
        st.write(data)

        # Display the continent information
        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']:,})"
        )
        # Country with min population
        st.write(
            f"Min Population:{data['min_population']['country']} "
            f"({data['min_population']['population']:,})"
        )

        # countries_data=data['countries']
        # country_df = pd.DataFrame(countries_data)
        # st.subheader(f"Population of Countries in {data['continent']}")
        # st.bar_chart(country_df.set_index("Country"))z
    else:
        # Handle errors
        st.error(f"Error: {response.json()['detail']}")