Spaces:
Sleeping
Sleeping
Commit Β·
d992864
1
Parent(s): c002138
add changes
Browse files- Dockerfile +16 -0
- app.py +57 -0
- requirements.txt +2 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# you will also find guides on how best to write your Dockerfile
|
| 3 |
+
|
| 4 |
+
FROM python:3.9
|
| 5 |
+
|
| 6 |
+
RUN useradd -m -u 1000 user
|
| 7 |
+
USER user
|
| 8 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 9 |
+
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 13 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 14 |
+
|
| 15 |
+
COPY --chown=user . /app
|
| 16 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# Set Streamlit page config
|
| 5 |
+
st.set_page_config(
|
| 6 |
+
page_title="World Population Dashboard",
|
| 7 |
+
page_icon="π",
|
| 8 |
+
layout="centered"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
API_URL = "https://velmurugan1122-backend.hf.space"
|
| 12 |
+
|
| 13 |
+
st.title("π World Population Dashboard")
|
| 14 |
+
st.subheader("Get insights into global population statistics")
|
| 15 |
+
|
| 16 |
+
# Continent selection
|
| 17 |
+
continents = ["Asia", "Africa", "Europe", "North America", "South America", "Australia", "Antarctica"]
|
| 18 |
+
selected_continent = st.selectbox("π Select a Continent", continents)
|
| 19 |
+
|
| 20 |
+
if selected_continent:
|
| 21 |
+
try:
|
| 22 |
+
# Fetch general population stats
|
| 23 |
+
response = requests.get(f"{API_URL}/{selected_continent}")
|
| 24 |
+
max_pop_resp = requests.get(f"{API_URL}/continent/{selected_continent}/max_population_country")
|
| 25 |
+
min_pop_resp = requests.get(f"{API_URL}/continent/{selected_continent}/min_population_country")
|
| 26 |
+
avg_pop_resp = requests.get(f"{API_URL}/continent/{selected_continent}/avg_population_country")
|
| 27 |
+
|
| 28 |
+
if response.status_code == 200:
|
| 29 |
+
stats = response.json()
|
| 30 |
+
max_data = max_pop_resp.json() if max_pop_resp.status_code == 200 else {}
|
| 31 |
+
min_data = min_pop_resp.json() if min_pop_resp.status_code == 200 else {}
|
| 32 |
+
avg_data = avg_pop_resp.json() if avg_pop_resp.status_code == 200 else {}
|
| 33 |
+
|
| 34 |
+
st.write("### π Overall Continent Population Stats")
|
| 35 |
+
st.write(f"π **Max Population:** {stats['max_population']:,}")
|
| 36 |
+
st.write(f"π **Min Population:** {stats['min_population']:,}")
|
| 37 |
+
st.write(f"π **Avg Population:** {stats['avg_population']:,}")
|
| 38 |
+
|
| 39 |
+
st.write("---")
|
| 40 |
+
|
| 41 |
+
# Max Population Country
|
| 42 |
+
if max_data:
|
| 43 |
+
st.success(f"π **Most Populated Country:** {max_data['country']} ({max_data['max_population']:,})")
|
| 44 |
+
|
| 45 |
+
# Min Population Country
|
| 46 |
+
if min_data:
|
| 47 |
+
st.warning(f"π **Least Populated Country:** {min_data['country']} ({min_data['min_population']:,})")
|
| 48 |
+
|
| 49 |
+
# Avg Population Country
|
| 50 |
+
if avg_data:
|
| 51 |
+
st.info(f"π **Closest to Avg Population:** {avg_data['country']} ({avg_data['max_population']:,})")
|
| 52 |
+
|
| 53 |
+
else:
|
| 54 |
+
st.error("β οΈ Failed to fetch population data.")
|
| 55 |
+
|
| 56 |
+
except requests.RequestException as e:
|
| 57 |
+
st.error(f"β API Request Failed: {e}")
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
requests
|