Vela commited on
Commit
40fc29c
·
1 Parent(s): 829bd84

Added few streamlit_functions

Browse files
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
@@ -12,36 +12,13 @@ csv_file = "./world_population.csv"
12
  if csv_file:
13
  choosen_data = streamlit_functions.choose_data_view(st)
14
  if choosen_data == "Show All Continents":
15
- opt = choosen_data.replace(" ","")
16
- streamlit_functions.display_contents(opt, st)
17
  if choosen_data == "Show All Countries":
18
- opt = choosen_data.replace(" ","")
19
- streamlit_functions.display_contents(opt, st)
20
- if choosen_data == "Show Continent with Highest Population":
21
- opt = choosen_data.replace(" ","")
22
- streamlit_functions.display_contents(opt, st)
23
- if choosen_data == "Show Continent with Lowest Population":
24
- opt = choosen_data.replace(" ","")
25
- streamlit_functions.display_contents(opt, st)
26
- if choosen_data == "Show Country with Highest Population":
27
- opt = choosen_data.replace(" ","")
28
- streamlit_functions.display_contents(opt, st)
29
- if choosen_data == "Show Country with Lowest Population":
30
- opt = choosen_data.replace(" ","")
31
- streamlit_functions.display_contents(opt, st)
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
- # selected_stat = st.selectbox("Select the stat",stat_list)
42
- # list_of_selected_cont = home_page.list_country_by_continent(df,selected_continent)
43
- # selected_key = st.selectbox("Select the key's to fetch data:",df.keys())
44
- # max_population = home_page.get_continent_with_max_pop(df)
45
- # st.write(f"Countries data in {selected_continent}:", list_of_selected_cont)
46
- # st.write(f"{selected_continent}'s with max population is :",max_population)
47
 
 
12
  if csv_file:
13
  choosen_data = streamlit_functions.choose_data_view(st)
14
  if choosen_data == "Show All Continents":
15
+ option = choosen_data.replace(" ","")
16
+ streamlit_functions.display_contents(option, st)
17
  if choosen_data == "Show All Countries":
18
+ option = choosen_data.replace(" ","")
19
+ streamlit_functions.display_contents(option, st)
20
+ if choosen_data == "Show Continent Stats":
21
+ streamlit_functions.display_stats(st,choosen_data)
22
+ if choosen_data == "Show Country Stats":
23
+ streamlit_functions.display_stats(st,choosen_data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
app/requests_app.py CHANGED
@@ -2,4 +2,5 @@ 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()
 
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
@@ -3,20 +3,29 @@ 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)
@@ -25,40 +34,11 @@ def display_contents(option, streamlit):
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
-
 
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
+ import pandas as pd
7
 
8
  def choose_data_view(st_interface):
9
  data_view_options = [
10
  "Select an option",
11
  "Show All Continents",
12
  "Show All Countries",
13
+ "Show Continent Stats",
14
+ "Show Country Stats",
 
 
15
  ]
16
  selected_option = st_interface.selectbox("Select Data to Display", data_view_options)
17
  return selected_option
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)
 
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)
40
+ if attribute in ["Population","Area"] :
41
+ stat = choose_stat_to_view(streamlit)
42
+ if stat in ["highest" , "lowest"]:
43
+ option = f"{clean_choosen_data}/{attribute}/{stat}"
44
+ display_contents(option,streamlit)