Kabila22 commited on
Commit
6b0d60a
·
1 Parent(s): 7902024

First commit

Browse files
Files changed (3) hide show
  1. Dockerfile +17 -0
  2. app.py +53 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a lightweight Python image as the base
2
+ FROM python:3.9-slim
3
+
4
+ # Set the working directory
5
+ WORKDIR /app
6
+
7
+ # Copy the project files to the container
8
+ COPY . /app
9
+
10
+ # Install dependencies
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ # Expose Streamlit's default port
14
+ EXPOSE 8501
15
+
16
+ # Command to run the Streamlit app
17
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import pandas as pd
4
+
5
+ # Function to get data from FastAPI
6
+ def get_continent_population(continent_name):
7
+ url = f"https://kabila22-backend.hf.space"
8
+ response = requests.get(url)
9
+ if response.status_code == 200:
10
+ return response.json()
11
+ else:
12
+ st.error("Failed to retrieve data")
13
+ return None
14
+
15
+ # List of continents
16
+ continents = ["Africa", "Asia", "Europe", "North America", "Oceania", "South America"]
17
+
18
+ # Create Streamlit dropdown box
19
+ st.title("World Population by Continent")
20
+ selected_continent = st.selectbox("Select a continent:", continents)
21
+
22
+ # Get data for selected continent
23
+ continent_data = get_continent_population(selected_continent)
24
+
25
+ if continent_data:
26
+ # Display population data in a table
27
+ st.subheader(f"Population Data for {selected_continent}")
28
+
29
+ # Ensure all values are present and convert them to numeric if necessary
30
+ population_data = {
31
+ "Data": ["Total Population", "Total Area", "Population Density", "Max Population", "Min Population", "Avg Population"],
32
+ "Result": [
33
+ continent_data.get("total_population", 0),
34
+ continent_data.get("total_area_km2", 0),
35
+ continent_data.get("continent_population_density", 0),
36
+ continent_data["max_population"].get("population", 0),
37
+ continent_data["min_population"].get("population", 0),
38
+ continent_data.get("avg_population", 0)
39
+ ],
40
+ "Country": [
41
+ "",
42
+ "",
43
+ "",
44
+ continent_data["max_population"]["country"],
45
+ continent_data["min_population"]["country"],
46
+ ""
47
+ ]
48
+ }
49
+
50
+ df = pd.DataFrame(population_data)
51
+
52
+ # Display the data in a table
53
+ st.table(df)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ requests
3
+ pandas