changed
Browse files
app.py
CHANGED
|
@@ -1,52 +1,37 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
-
import pandas as pd
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
st.error("Page not found. Redirecting to the main dashboard...")
|
| 8 |
-
st.query_params["page"] = ""
|
| 9 |
-
st.rerun()
|
| 10 |
-
|
| 11 |
-
# Set the FastAPI base URL
|
| 12 |
-
API_URL = "https://tharu22-world-population.hf.space"
|
| 13 |
|
| 14 |
-
# Streamlit
|
| 15 |
-
st.title("World Population Dashboard")
|
| 16 |
|
| 17 |
-
# Sidebar filter
|
| 18 |
st.sidebar.header("Filter")
|
| 19 |
selected_continent = st.sidebar.selectbox(
|
| 20 |
-
"Select
|
| 21 |
-
[
|
| 22 |
)
|
| 23 |
|
| 24 |
-
# Fetch data from the FastAPI endpoint
|
| 25 |
if st.sidebar.button("Get Data"):
|
| 26 |
-
# Call FastAPI
|
| 27 |
response = requests.get(f"{API_URL}/{selected_continent}")
|
| 28 |
-
|
| 29 |
if response.status_code == 200:
|
| 30 |
data = response.json()
|
| 31 |
-
|
| 32 |
-
st.
|
| 33 |
-
|
| 34 |
-
# Display
|
| 35 |
-
|
| 36 |
-
st.
|
| 37 |
-
st.
|
| 38 |
-
st.
|
| 39 |
-
st.
|
| 40 |
-
st.write(
|
| 41 |
-
|
| 42 |
-
f"({data['max_population']['population']:,})"
|
| 43 |
-
)
|
| 44 |
-
# Country with min population
|
| 45 |
-
st.write(
|
| 46 |
-
f"Min Population:{data['min_population']['country']} "
|
| 47 |
-
f"({data['min_population']['population']:,})"
|
| 48 |
-
)
|
| 49 |
else:
|
| 50 |
-
# Handle errors
|
| 51 |
st.error(f"Error: {response.json()['detail']}")
|
| 52 |
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
|
|
|
| 3 |
|
| 4 |
+
# Set FastAPI backend URL
|
| 5 |
+
API_URL = "https://your-fastapi-space.hf.space" # Change to your actual FastAPI URL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Streamlit UI
|
| 8 |
+
st.title("π World Population Dashboard")
|
| 9 |
|
| 10 |
+
# Sidebar filter
|
| 11 |
st.sidebar.header("Filter")
|
| 12 |
selected_continent = st.sidebar.selectbox(
|
| 13 |
+
"Select a Continent:",
|
| 14 |
+
["Asia", "Africa", "North America", "South America", "Europe", "Oceania"]
|
| 15 |
)
|
| 16 |
|
|
|
|
| 17 |
if st.sidebar.button("Get Data"):
|
| 18 |
+
# Call FastAPI
|
| 19 |
response = requests.get(f"{API_URL}/{selected_continent}")
|
| 20 |
+
|
| 21 |
if response.status_code == 200:
|
| 22 |
data = response.json()
|
| 23 |
+
|
| 24 |
+
st.header(f"π {selected_continent} - Population Statistics")
|
| 25 |
+
|
| 26 |
+
# Display data in Streamlit
|
| 27 |
+
st.write(f"π’ **Max Population:** {data['Max']}")
|
| 28 |
+
st.write(f"π΄ **Min Population:** {data['Min']}")
|
| 29 |
+
st.write(f"π **Average Population:** {data['Avgerage']}")
|
| 30 |
+
st.write(f"π **Total Area:** {data['Area']}")
|
| 31 |
+
st.write(f"π₯ **Total Population:** {data['Sum']}")
|
| 32 |
+
st.write(f"π **Population Density:** {data['density']}")
|
| 33 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
else:
|
|
|
|
| 35 |
st.error(f"Error: {response.json()['detail']}")
|
| 36 |
|
| 37 |
+
|