velmurugan1122 commited on
Commit
d992864
Β·
1 Parent(s): c002138

add changes

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +57 -0
  3. 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