Chittrarasu commited on
Commit
b6327f4
·
0 Parent(s):

frontend deployment

Browse files
Files changed (4) hide show
  1. Dockerfile +21 -0
  2. README.md +8 -0
  3. app.py +50 -0
  4. requirements.txt +0 -0
Dockerfile ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Python 3.11 as the base image
2
+ FROM python:3.11-slim
3
+
4
+ # Set the working directory inside the container
5
+ WORKDIR /app
6
+
7
+ # Copy all project files into the container
8
+ COPY . /app
9
+
10
+ # Install dependencies
11
+ RUN pip install --upgrade pip
12
+ RUN pip install --no-cache-dir -r requirement.txt
13
+
14
+ # Set PYTHONPATH so FastAPI can find the 'backend' module
15
+ ENV PYTHONPATH=/app
16
+
17
+ # Expose the required port
18
+ EXPOSE 7860
19
+
20
+ # Start FastAPI with the correct module path
21
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Population Streamlit
3
+ emoji: 🚀
4
+ colorFrom: yellow
5
+ colorTo: purple
6
+ sdk: docker
7
+ pinned: false
8
+ ---
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ # FastAPI backend URL
5
+ FASTAPI_URL = "https://chittrarasu-population-fastapi.hf.space"
6
+
7
+ # Streamlit app
8
+ st.title("World Population Statistics")
9
+
10
+ # Fetch all continents
11
+ response = requests.get(f"{FASTAPI_URL}/continents/")
12
+ if response.status_code == 200:
13
+ continents = response.json().get("continents", [])
14
+ else:
15
+ st.error("Failed to fetch continents")
16
+ continents = []
17
+
18
+ # Dropdown to select a continent
19
+ selected_continent = st.selectbox("Select a Continent", continents)
20
+
21
+ if selected_continent:
22
+ # Fetch statistics for the selected continent
23
+ response = requests.get(f"{FASTAPI_URL}/continents/{selected_continent}/")
24
+
25
+ if response.status_code == 200:
26
+ continent_data = response.json()
27
+ st.subheader(f"Statistics for {selected_continent}")
28
+
29
+ # Check if 'statistics' is in response
30
+ statistics = continent_data.get("statistics", {})
31
+ if statistics:
32
+ st.write(f"**Total Countries:** {statistics.get('Total_Countries', 'N/A')}")
33
+ st.write(f"**Total Population:** {statistics.get('Total_Population', 'N/A')}")
34
+ st.write(f"**Average Population:** {statistics.get('Average_Population', 'N/A')}")
35
+ st.write(f"**Total Area:** {statistics.get('Total_Area', 'N/A')}")
36
+ st.write(f"**Max Population:** {statistics.get('max_population', 'N/A')}")
37
+ st.write(f"**Min Population:** {statistics.get('min_population', 'N/A')}")
38
+ st.write(f"**Country with Max Population:** {statistics.get('Country_Max_Population', 'N/A')}")
39
+ st.write(f"**Country with Min Population:** {statistics.get('Country_Min_Population', 'N/A')}")
40
+ st.write(f"**Population Density:** {statistics.get('Population_Density', 'N/A')}")
41
+ else:
42
+ st.error("No statistics found for this continent.")
43
+ else:
44
+ st.error(f"Failed to fetch statistics for {selected_continent}")
45
+
46
+ # Option to view a specific statistic
47
+ if statistics:
48
+ stat_options = list(statistics.keys())
49
+ selected_stat = st.selectbox("Select a specific statistic to view", stat_options)
50
+ st.write(f"**{selected_stat}:** {statistics.get(selected_stat, 'N/A')}")
requirements.txt ADDED
Binary file (2.42 kB). View file