Spaces:
Sleeping
Sleeping
Vela
commited on
Commit
·
fe475ff
1
Parent(s):
a4d99c7
added streamlit file
Browse files- .gitignore +1 -0
- Dockerfile +13 -0
- app/__pycache__/requests_app.cpython-312.pyc +0 -0
- app/__pycache__/streamlit_app.cpython-312.pyc +0 -0
- app/__pycache__/streamlit_functions.cpython-312.pyc +0 -0
- app/app.py +46 -0
- app/requests_app.py +5 -0
- app/streamlit_functions.py +64 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.venv
|
Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
RUN useradd -m -u 1000 user
|
4 |
+
USER user
|
5 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
6 |
+
|
7 |
+
WORKDIR /code
|
8 |
+
|
9 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
10 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
11 |
+
|
12 |
+
COPY --chown=user . /app
|
13 |
+
CMD ["streamlit", "run", "app/app.py", "--server.address", "0.0.0.0", "--server.port", "8501"]
|
app/__pycache__/requests_app.cpython-312.pyc
ADDED
Binary file (536 Bytes). View file
|
|
app/__pycache__/streamlit_app.cpython-312.pyc
ADDED
Binary file (1.75 kB). View file
|
|
app/__pycache__/streamlit_functions.cpython-312.pyc
ADDED
Binary file (1.63 kB). View file
|
|
app/app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
src_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..", "frontend"))
|
4 |
+
sys.path.append(src_directory)
|
5 |
+
import streamlit as st
|
6 |
+
import streamlit_functions
|
7 |
+
|
8 |
+
st.title("World Population Data")
|
9 |
+
csv_file = st.file_uploader("Choose a CSV file", type=['csv'])
|
10 |
+
|
11 |
+
if csv_file:
|
12 |
+
choosen_data = streamlit_functions.choose_data_view(st)
|
13 |
+
if choosen_data == "Show All Continents":
|
14 |
+
opt = choosen_data.replace(" ","")
|
15 |
+
streamlit_functions.display_contents(opt, st)
|
16 |
+
if choosen_data == "Show All Countries":
|
17 |
+
opt = choosen_data.replace(" ","")
|
18 |
+
streamlit_functions.display_contents(opt, st)
|
19 |
+
if choosen_data == "Show Continent with Highest Population":
|
20 |
+
opt = choosen_data.replace(" ","")
|
21 |
+
streamlit_functions.display_contents(opt, st)
|
22 |
+
if choosen_data == "Show Continent with Lowest Population":
|
23 |
+
opt = choosen_data.replace(" ","")
|
24 |
+
streamlit_functions.display_contents(opt, st)
|
25 |
+
if choosen_data == "Show Country with Highest Population":
|
26 |
+
opt = choosen_data.replace(" ","")
|
27 |
+
streamlit_functions.display_contents(opt, st)
|
28 |
+
if choosen_data == "Show Country with Lowest Population":
|
29 |
+
opt = choosen_data.replace(" ","")
|
30 |
+
streamlit_functions.display_contents(opt, st)
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
# selected_stat = st.selectbox("Select the stat",stat_list)
|
41 |
+
# list_of_selected_cont = home_page.list_country_by_continent(df,selected_continent)
|
42 |
+
# selected_key = st.selectbox("Select the key's to fetch data:",df.keys())
|
43 |
+
# max_population = home_page.get_continent_with_max_pop(df)
|
44 |
+
# st.write(f"Countries data in {selected_continent}:", list_of_selected_cont)
|
45 |
+
# st.write(f"{selected_continent}'s with max population is :",max_population)
|
46 |
+
|
app/requests_app.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
def get_api(end_point : str = None):
|
4 |
+
r = requests.get(f"https://velatest-world-data-insights-api.hf.space/{end_point}")
|
5 |
+
return r.json()
|
app/streamlit_functions.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
src_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..", "main"))
|
4 |
+
sys.path.append(src_directory)
|
5 |
+
import requests_app
|
6 |
+
|
7 |
+
def choose_data_view(st_interface):
|
8 |
+
data_view_options = [
|
9 |
+
"Select an option",
|
10 |
+
"Show All Continents",
|
11 |
+
"Show All Countries",
|
12 |
+
"Show Continent with Highest Population",
|
13 |
+
"Show Continent with Lowest Population",
|
14 |
+
"Show Country with Highest Population",
|
15 |
+
"Show Country with Lowest Population"
|
16 |
+
]
|
17 |
+
selected_option = st_interface.selectbox("Select Data to Display", data_view_options)
|
18 |
+
return selected_option
|
19 |
+
|
20 |
+
def display_contents(option, streamlit):
|
21 |
+
try:
|
22 |
+
cont = requests_app.get_api(option)
|
23 |
+
continents = streamlit.table(cont)
|
24 |
+
return continents
|
25 |
+
except Exception as e:
|
26 |
+
streamlit.error(f"An error occurred while processing the CSV: {e}")
|
27 |
+
|
28 |
+
# def display_countries(option, streamlit):
|
29 |
+
# cont = requests_app.get_api(option)
|
30 |
+
# return streamlit.table(cont)
|
31 |
+
|
32 |
+
# def display_continent_with_highest_population(option, streamlit):
|
33 |
+
# cont = requests_app.get_api(option)
|
34 |
+
# return streamlit.table(cont)
|
35 |
+
|
36 |
+
# def display_country_by_continents(selected_continent,streamlit):
|
37 |
+
# if selected_continent is not "Choose a continent to display countries":
|
38 |
+
# countries_list = requests_app.get_api(selected_continent)
|
39 |
+
# streamlit.table(countries_list)
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
# else:
|
58 |
+
# streamlit.warning("Please select a valid continent.")
|
59 |
+
# selected_continent = streamlit.selectbox(
|
60 |
+
# "Select a continent",["Choose a continent to display countries"] + list(df['Continent'].unique()),)
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
requests
|