velmurugan1122 commited on
Commit
0ff6151
Β·
1 Parent(s): c3756d0

fix : changes

Browse files
Files changed (3) hide show
  1. Dockerfile +1 -2
  2. app.py +33 -50
  3. request_response.py +9 -0
Dockerfile CHANGED
@@ -1,5 +1,4 @@
1
- # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
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
- # Set Streamlit page config
5
- st.set_page_config(
6
- page_title="World Population Dashboard",
7
- page_icon="🌍",
8
- layout="centered"
9
- )
10
 
11
- API_URL = "https://velmurugan1122-backend.hf.space"
 
 
12
 
13
  st.title("🌍 World Population Dashboard")
14
  st.subheader("Get insights into global population statistics")
15
-
16
- # Continent selection
17
- continents = ["Asia", "Africa", "Europe", "North America", "South America", "Australia", "Antarctica"]
18
- selected_continent = st.selectbox("🌎 Select a Continent", continents)
19
-
20
- if selected_continent:
21
- try:
22
- # Fetch general population stats
23
- response = requests.get(f"{API_URL}/{selected_continent}")
24
- max_pop_resp = requests.get(f"{API_URL}/continent/{selected_continent}/max_population_country")
25
- min_pop_resp = requests.get(f"{API_URL}/continent/{selected_continent}/min_population_country")
26
- avg_pop_resp = requests.get(f"{API_URL}/continent/{selected_continent}/avg_population_country")
27
-
28
- if response.status_code == 200:
29
- stats = response.json()
30
- max_data = max_pop_resp.json() if max_pop_resp.status_code == 200 else {}
31
- min_data = min_pop_resp.json() if min_pop_resp.status_code == 200 else {}
32
- avg_data = avg_pop_resp.json() if avg_pop_resp.status_code == 200 else {}
33
-
34
- st.write("### 🌟 Overall Continent Population Stats")
35
- st.write(f"πŸ“ˆ **Max Population:** {stats['max_population']:,}")
36
- st.write(f"πŸ“‰ **Min Population:** {stats['min_population']:,}")
37
- st.write(f"πŸ“Š **Avg Population:** {stats['avg_population']:,}")
38
-
39
- st.write("---")
40
-
41
- # Max Population Country
42
- if max_data:
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()