Ezhil commited on
Commit
263a93d
·
1 Parent(s): 2c36732

1st change

Browse files
Files changed (3) hide show
  1. Dockerfile +21 -0
  2. app.py +51 -0
  3. requirements.txt +0 -0
Dockerfile ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Python runtime as a parent image
2
+ FROM python:3.11
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+
8
+ # Copy the application files
9
+ COPY . .
10
+
11
+ # Install dependencies
12
+ RUN pip install -r requirements.txt
13
+
14
+
15
+ # Expose the ports for FastAPI (8000) and Streamlit (8501)
16
+ EXPOSE 7860
17
+
18
+ # Run FastAPI and Streamlit in parallel
19
+ CMD ["sh", "-c", "uvicorn app:app --host 0.0.0.0 --port 7860"]
20
+
21
+
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ # FastAPI backend URL (assuming it's running on localhost)
5
+ API_URL = "http://127.0.0.1:8000/"
6
+
7
+ # Define function to get continent stats from FastAPI backend
8
+ def get_continent_stats(continent):
9
+ response = requests.get(f"{API_URL}{continent}/")
10
+ if response.status_code == 200:
11
+ return response.json()
12
+ else:
13
+ st.error("Failed to fetch data")
14
+ return None
15
+
16
+ # Streamlit user interface
17
+ st.title("World Population and Statistics by Continent")
18
+
19
+ # Sidebar for continent and function selection
20
+ st.sidebar.header("Options")
21
+ continent = st.sidebar.selectbox("Select Continent:", ['Africa', 'Asia', 'Europe', 'North America', 'South America', 'Oceania'])
22
+ function = st.sidebar.selectbox("Choose statistic to display:", [
23
+ "Total Countries",
24
+ "Total Population",
25
+ "Average Population",
26
+ "Total Area",
27
+ "Max Population",
28
+ "Min Population",
29
+ "Population Density"
30
+ ])
31
+
32
+ # Fetch the data when a continent is selected
33
+ continent_data = get_continent_stats(continent)
34
+
35
+ if continent_data:
36
+ # Display the statistics based on selected function
37
+ st.subheader(f"{function} in {continent}")
38
+ if function == "Total Countries":
39
+ st.write(f"Total Countries: {continent_data['Total_Countries']}")
40
+ elif function == "Total Population":
41
+ st.write(f"Total Population: {continent_data['Total_Population']}")
42
+ elif function == "Average Population":
43
+ st.write(f"Average Population: {continent_data['Average_Population']}")
44
+ elif function == "Total Area":
45
+ st.write(f"Total Area (km²): {continent_data['Total_Area']}")
46
+ elif function == "Max Population":
47
+ st.write(f"Maximum Population: {continent_data['max_population']}")
48
+ elif function == "Min Population":
49
+ st.write(f"Minimum Population: {continent_data['min_population']}")
50
+ elif function == "Population Density":
51
+ st.write(f"Population Density (per km²): {continent_data['Population_Density']}")
requirements.txt ADDED
Binary file (2.46 kB). View file