logeswari/frontend
0
1import streamlit as st2import requests3import pandas as pd4 5 6# Redirect /docs to the main page7if st.experimental_get_query_params().get("page", [""])[0] == "docs":8 st.error("Page not found. Redirecting to the main dashboard...")9 st.experimental_set_query_params(page="")10 st.experimental_rerun()11 12# Set the FastAPI base URL13API_URL = "https://logeswari-backapp.hf.space"14 15# Streamlit app title16st.title("⭐World Population Dashboard")17 18# Sidebar filter for continents19st.sidebar.header("Filter")20selected_continent = st.sidebar.selectbox(21 "Select the Continent:",22 ['Asia', 'Africa', 'North America', 'South America', 'Europe', 'Oceania']23)24 25# Fetch data from the FastAPI endpoint26if st.sidebar.button("Get Data"):27 # Call FastAPI to get continent data28 response = requests.get(f"{API_URL}/continent/{selected_continent}")29 30 if response.status_code == 200:31 data = response.json()32 st.write(data)33 34 # Display the continent information35 st.header(f"Data of {data['continent']}")36 st.metric("Total Population", f"{data['total_population']:,}")37 st.metric("Total Area (sq km)", f"{data['total_area']:,}")38 st.metric("Population Density", f"{data['continent_population_density']:.2f}")39 st.subheader("Population Highlights")40 st.write(41 f"Max Population :{data['max_population']['country']} "42 f"({data['max_population']['population']:,})"43 )44 # Country with min population45 st.write(46 f"Min Population:{data['min_population']['country']} "47 f"({data['min_population']['population']:,})"48 )49 50 # countries_data=data['countries']51 # country_df = pd.DataFrame(countries_data)52 # st.subheader(f"Population of Countries in {data['continent']}")53 # st.bar_chart(country_df.set_index("Country"))z54 else:55 # Handle errors56 st.error(f"Error: {response.json()['detail']}")57 58 59 