File size: 2,129 Bytes
263a93d
 
 
 
78268fb
263a93d
13745e6
 
 
263a93d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests

# FastAPI backend URL (assuming it's running on localhost)
API_URL = "https://ezhil24-backend.hf.space/"

# Streamlit config for Hugging Face compatibility
st.set_page_config(page_title="World Population Statistics", layout="wide")

# Define function to get continent stats from FastAPI backend
def get_continent_stats(continent):
    response = requests.get(f"{API_URL}{continent}/")
    if response.status_code == 200:
        return response.json()
    else:
        st.error("Failed to fetch data")
        return None

# Streamlit user interface
st.title("World Population and Statistics by Continent")

# Sidebar for continent and function selection
st.sidebar.header("Options")
continent = st.sidebar.selectbox("Select Continent:", ['Africa', 'Asia', 'Europe', 'North America', 'South America', 'Oceania'])
function = st.sidebar.selectbox("Choose statistic to display:", [
    "Total Countries", 
    "Total Population", 
    "Average Population", 
    "Total Area", 
    "Max Population", 
    "Min Population", 
    "Population Density"
])

# Fetch the data when a continent is selected
continent_data = get_continent_stats(continent)

if continent_data:
    # Display the statistics based on selected function
    st.subheader(f"{function} in {continent}")
    if function == "Total Countries":
        st.write(f"Total Countries: {continent_data['Total_Countries']}")
    elif function == "Total Population":
        st.write(f"Total Population: {continent_data['Total_Population']}")
    elif function == "Average Population":
        st.write(f"Average Population: {continent_data['Average_Population']}")
    elif function == "Total Area":
        st.write(f"Total Area (km²): {continent_data['Total_Area']}")
    elif function == "Max Population":
        st.write(f"Maximum Population: {continent_data['max_population']}")
    elif function == "Min Population":
        st.write(f"Minimum Population: {continent_data['min_population']}")
    elif function == "Population Density":
        st.write(f"Population Density (per km²): {continent_data['Population_Density']}")