File size: 1,588 Bytes
0f15b2f
c865e04
0f15b2f
9b9aff0
d079d0c
c865e04
9b9aff0
 
c865e04
9b9aff0
c865e04
 
9b9aff0
 
c865e04
 
 
9b9aff0
3564f89
 
9b9aff0
3564f89
 
ddc1a61
9b9aff0
3564f89
1ae8791
3564f89
 
 
ddc1a61
3564f89
 
 
9b9aff0
3564f89
 
 
 
 
 
 
ddc1a61
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
import streamlit as st
import requests

# Set FastAPI backend URL
API_URL = "https://tharu22-world-population.hf.space"  # Change to your actual FastAPI URL

# Streamlit UI
st.title("🌍 World Population Dashboard")

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

if st.sidebar.button("Get Data"):
    # Call FastAPI
    try:
        response = requests.get(f"{API_URL}/{selected_continent}", timeout=10)

        if response.status_code == 200:
            try:
                data = response.json()

                st.header(f"πŸ“Š {selected_continent} - Population Statistics")

                # Display data in Streamlit
                st.write(f"🟒 **Max Population:** {data.get('Max', 'N/A')}")
                st.write(f"πŸ”΄ **Min Population:** {data.get('Min', 'N/A')}")
                st.write(f"πŸ“‰ **Average Population:** {data.get('Avgerage', 'N/A')}")
                st.write(f"🌎 **Total Area:** {data.get('Area', 'N/A')}")
                st.write(f"πŸ‘₯ **Total Population:** {data.get('Sum', 'N/A')}")
                st.write(f"πŸ— **Population Density:** {data.get('density', 'N/A')}")

            except requests.exceptions.JSONDecodeError:
                st.error(f"Invalid JSON response received:\n{response.text}")

        else:
            st.error(f"API Error {response.status_code}: {response.text}")

    except requests.exceptions.RequestException as e:
        st.error(f"Request failed: {e}")