Spaces:
Sleeping
Sleeping
Commit Β·
0ff6151
1
Parent(s): c3756d0
fix : changes
Browse files- Dockerfile +1 -2
- app.py +33 -50
- request_response.py +9 -0
Dockerfile
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
# you will also find guides on how best to write your Dockerfile
|
| 3 |
|
| 4 |
FROM python:3.9
|
| 5 |
|
|
|
|
| 1 |
+
|
|
|
|
| 2 |
|
| 3 |
FROM python:3.9
|
| 4 |
|
app.py
CHANGED
|
@@ -1,57 +1,40 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import requests
|
| 3 |
|
| 4 |
-
|
| 5 |
-
st.set_page_config(
|
| 6 |
-
page_title="World Population Dashboard",
|
| 7 |
-
page_icon="π",
|
| 8 |
-
layout="centered"
|
| 9 |
-
)
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
st.title("π World Population Dashboard")
|
| 14 |
st.subheader("Get insights into global population statistics")
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
if
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 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}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
# from front_end import request_response
|
| 3 |
import requests
|
| 4 |
|
| 5 |
+
API_URL = "http://127.0.0.1:8000"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def get_response(end_point:str = None):
|
| 8 |
+
response = requests.get(f"{API_URL}/{end_point}")
|
| 9 |
+
return response.json()
|
| 10 |
|
| 11 |
st.title("π World Population Dashboard")
|
| 12 |
st.subheader("Get insights into global population statistics")
|
| 13 |
+
choosen_option = st.selectbox("Select an option", ["select any","Continents",
|
| 14 |
+
"Country","Continent Stats", "Country Stats"])
|
| 15 |
+
if choosen_option == "Continents":
|
| 16 |
+
continents = get_response(choosen_option.lower())
|
| 17 |
+
cont = st.table(continents)
|
| 18 |
+
if choosen_option == "Country":
|
| 19 |
+
country = get_response(choosen_option.lower())
|
| 20 |
+
country_data = st.table(country)
|
| 21 |
+
|
| 22 |
+
if choosen_option == "Continent Stats":
|
| 23 |
+
option = choosen_option.replace(" ","_").lower()
|
| 24 |
+
choosen_attribute = st.selectbox("Select an option",["Choose Attribute","Population","Area"])
|
| 25 |
+
if choosen_attribute in ["Population","Area"]:
|
| 26 |
+
choosen_stat = st.selectbox("Select an option",["Choose Stat","highest","lowest"])
|
| 27 |
+
if choosen_stat in ["highest", "lowest"]:
|
| 28 |
+
end_point = f"{option}/{choosen_attribute}/{choosen_stat}"
|
| 29 |
+
continet_stats = get_response(end_point)
|
| 30 |
+
cont_stats = st.table(continet_stats)
|
| 31 |
+
|
| 32 |
+
if choosen_option == "Country Stats":
|
| 33 |
+
option = choosen_option.replace(" ","_").lower()
|
| 34 |
+
choosen_attribute = st.selectbox("Select an option",["Choose Attribute","Population","Area"])
|
| 35 |
+
if choosen_attribute in ["Population","Area"]:
|
| 36 |
+
choosen_stat = st.selectbox("Select an option",["Choose Stat","highest","lowest"])
|
| 37 |
+
if choosen_stat in ["highest", "lowest"]:
|
| 38 |
+
end_point = f"{option}/{choosen_attribute}/{choosen_stat}"
|
| 39 |
+
continet_stats = get_response(end_point)
|
| 40 |
+
cont_stats = st.table(continet_stats)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
request_response.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
API_URL = "http://127.0.0.1:8000/"
|
| 4 |
+
#
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def get_response(end_point):
|
| 8 |
+
response = requests.get(f"{API_URL}/{end_point}")
|
| 9 |
+
return response.json()
|