Spaces:
Sleeping
Sleeping
Vela
commited on
Commit
·
5191254
1
Parent(s):
b5a0d9e
Update few files
Browse files- app/__pycache__/requests_app.cpython-312.pyc +0 -0
- app/__pycache__/streamlit_functions.cpython-312.pyc +0 -0
- app/app.py +63 -15
- app/requests_app.py +3 -3
- app/streamlit_functions.py +37 -20
app/__pycache__/requests_app.cpython-312.pyc
CHANGED
Binary files a/app/__pycache__/requests_app.cpython-312.pyc and b/app/__pycache__/requests_app.cpython-312.pyc differ
|
|
app/__pycache__/streamlit_functions.cpython-312.pyc
CHANGED
Binary files a/app/__pycache__/streamlit_functions.cpython-312.pyc and b/app/__pycache__/streamlit_functions.cpython-312.pyc differ
|
|
app/app.py
CHANGED
@@ -4,21 +4,69 @@ src_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..",
|
|
4 |
sys.path.append(src_directory)
|
5 |
import streamlit as st
|
6 |
import streamlit_functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
st.title("World Population Data")
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
sys.path.append(src_directory)
|
5 |
import streamlit as st
|
6 |
import streamlit_functions
|
7 |
+
import pandas as pd
|
8 |
+
import matplotlib.pyplot as plt
|
9 |
+
|
10 |
+
def load_data(file):
|
11 |
+
try:
|
12 |
+
data = pd.read_csv(file)
|
13 |
+
return data
|
14 |
+
except Exception as e:
|
15 |
+
st.error(f"Error loading file: {e}")
|
16 |
+
return None
|
17 |
|
18 |
st.title("World Population Data")
|
19 |
+
st.sidebar.title("Navigation")
|
20 |
+
|
21 |
+
choosen_data = streamlit_functions.choose_data_to_view(st)
|
22 |
+
|
23 |
+
if choosen_data == "Show All Continents":
|
24 |
+
option = choosen_data.replace(" ", "")
|
25 |
+
streamlit_functions.display_contents(option, st)
|
26 |
+
|
27 |
+
elif choosen_data == "Show All Countries":
|
28 |
+
option = choosen_data.replace(" ", "")
|
29 |
+
streamlit_functions.display_contents(option, st)
|
30 |
+
|
31 |
+
elif choosen_data == "Show Continent Stats":
|
32 |
+
streamlit_functions.display_stats(st, choosen_data)
|
33 |
+
|
34 |
+
elif choosen_data == "Show Country Stats":
|
35 |
+
streamlit_functions.display_stats(st, choosen_data)
|
36 |
+
|
37 |
+
elif choosen_data == "Show Continent Wise Data":
|
38 |
+
clean_choosen_data = choosen_data.replace(" ", "")
|
39 |
+
attribute = streamlit_functions.choose_attribute_to_view(st)
|
40 |
+
if attribute in ["Population","Area"]:
|
41 |
+
option = f"{clean_choosen_data}/{attribute}"
|
42 |
+
streamlit_functions.display_contents(option,st)
|
43 |
+
|
44 |
+
elif choosen_data == "Show Country Data":
|
45 |
+
clean_choosen_data = choosen_data.replace(" ", "")
|
46 |
+
country_list = streamlit_functions.get_list("ShowAllCountries")
|
47 |
+
choosen_country = streamlit_functions.choose_data_from_list(st,country_list)
|
48 |
+
clean_country = choosen_country.replace(" ","").capitalize()
|
49 |
+
attribute = streamlit_functions.choose_attribute_to_view(st)
|
50 |
+
if attribute in ["Population","Area"]:
|
51 |
+
option = f"{clean_choosen_data}/{clean_country}/{attribute}"
|
52 |
+
streamlit_functions.display_contents(option,st)
|
53 |
|
54 |
+
elif choosen_data == "Upload Custom CSV":
|
55 |
+
uploaded_file = st.sidebar.file_uploader("Choose a CSV file", type=['csv'])
|
56 |
+
|
57 |
+
if uploaded_file is not None:
|
58 |
+
data = load_data(uploaded_file)
|
59 |
+
|
60 |
+
if data is not None:
|
61 |
+
st.write("Data Preview:", data.head())
|
62 |
+
|
63 |
+
if "Continent" in data.columns and "Population" in data.columns:
|
64 |
+
continent_data = data.groupby("Continent")["Population"].sum().reset_index()
|
65 |
+
st.write("Continent-wise Population Summary:", continent_data)
|
66 |
+
else:
|
67 |
+
st.warning("The uploaded CSV does not contain 'Continent' or 'Population' columns.")
|
68 |
+
|
69 |
+
else:
|
70 |
+
st.warning("There was an error loading the file. Please check the format and try again.")
|
71 |
+
else:
|
72 |
+
st.write("Please choose an option from the sidebar to view the data.")
|
app/requests_app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
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 |
-
|
6 |
-
return r.json()
|
|
|
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 |
+
r = requests.get(f"http://127.0.0.1:8000/{end_point}")
|
6 |
+
return r.json()
|
app/streamlit_functions.py
CHANGED
@@ -5,35 +5,52 @@ sys.path.append(src_directory)
|
|
5 |
import requests_app
|
6 |
import pandas as pd
|
7 |
|
8 |
-
def
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
def choose_stat_to_view(st_interface):
|
20 |
stat_options = ["Select an option","highest","lowest"]
|
21 |
-
selected_option = st_interface.selectbox("Select Stat to Display", stat_options)
|
22 |
return selected_option
|
23 |
|
24 |
def choose_attribute_to_view(st_interface):
|
25 |
attribute_options = ["Select an option","Population", "Area"]
|
26 |
-
selected_option = st_interface.selectbox("Select Attribute to Display", attribute_options)
|
27 |
return selected_option
|
28 |
|
29 |
-
def display_contents(option, streamlit):
|
30 |
-
try:
|
31 |
-
cont = requests_app.get_api(option)
|
32 |
-
continents = streamlit.table(cont)
|
33 |
-
return continents
|
34 |
-
except Exception as e:
|
35 |
-
streamlit.error(f"An error occurred while processing the CSV: {e}")
|
36 |
-
|
37 |
def display_stats(streamlit,choosen_data):
|
38 |
clean_choosen_data = choosen_data.replace(" ", "")
|
39 |
attribute = choose_attribute_to_view(streamlit)
|
|
|
5 |
import requests_app
|
6 |
import pandas as pd
|
7 |
|
8 |
+
def display_contents(option, streamlit):
|
9 |
+
try:
|
10 |
+
cont = requests_app.get_api(option)
|
11 |
+
continents = streamlit.table(cont)
|
12 |
+
return continents
|
13 |
+
except Exception as e:
|
14 |
+
streamlit.error(f"An error occurred while processing the CSV: {e}")
|
15 |
+
|
16 |
+
def get_list(option):
|
17 |
+
data = requests_app.get_api(option)
|
18 |
+
return data["Country"].values()
|
19 |
+
|
20 |
+
def choose_data_to_view(st_interface):
|
21 |
+
choosen_option = st_interface.sidebar.selectbox(
|
22 |
+
"Data Insights",
|
23 |
+
options=[
|
24 |
+
"Select an option",
|
25 |
+
"Show All Continents",
|
26 |
+
"Show Continent Wise Data",
|
27 |
+
"Show Continent Stats",
|
28 |
+
"Show All Countries",
|
29 |
+
"Show Country Data" ,
|
30 |
+
"Show Country Stats",
|
31 |
+
"Upload Custom CSV"
|
32 |
+
]
|
33 |
+
)
|
34 |
+
|
35 |
+
if choosen_option == "Select an option":
|
36 |
+
return None
|
37 |
+
return choosen_option
|
38 |
+
|
39 |
+
def choose_data_from_list(st_interface,list_option):
|
40 |
+
choosen_option = st_interface.sidebar.selectbox(
|
41 |
+
"Options",list_option)
|
42 |
+
return choosen_option
|
43 |
|
44 |
def choose_stat_to_view(st_interface):
|
45 |
stat_options = ["Select an option","highest","lowest"]
|
46 |
+
selected_option = st_interface.sidebar.selectbox("Select Stat to Display", stat_options)
|
47 |
return selected_option
|
48 |
|
49 |
def choose_attribute_to_view(st_interface):
|
50 |
attribute_options = ["Select an option","Population", "Area"]
|
51 |
+
selected_option = st_interface.sidebar.selectbox("Select Attribute to Display", attribute_options)
|
52 |
return selected_option
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
def display_stats(streamlit,choosen_data):
|
55 |
clean_choosen_data = choosen_data.replace(" ", "")
|
56 |
attribute = choose_attribute_to_view(streamlit)
|