tharu22 commited on
Commit
9b9aff0
Β·
1 Parent(s): 491a268
Files changed (1) hide show
  1. app.py +21 -36
app.py CHANGED
@@ -1,52 +1,37 @@
1
  import streamlit as st
2
  import requests
3
- import pandas as pd
4
 
5
- # Redirect /docs to the main page
6
- if st.query_params.get("page", "") == "docs":
7
- st.error("Page not found. Redirecting to the main dashboard...")
8
- st.query_params["page"] = ""
9
- st.rerun()
10
-
11
- # Set the FastAPI base URL
12
- API_URL = "https://tharu22-world-population.hf.space"
13
 
14
- # Streamlit app title
15
- st.title("World Population Dashboard")
16
 
17
- # Sidebar filter for continents
18
  st.sidebar.header("Filter")
19
  selected_continent = st.sidebar.selectbox(
20
- "Select the Continent:",
21
- ['Asia', 'Africa', 'North America', 'South America', 'Europe', 'Oceania']
22
  )
23
 
24
- # Fetch data from the FastAPI endpoint
25
  if st.sidebar.button("Get Data"):
26
- # Call FastAPI to get continent data
27
  response = requests.get(f"{API_URL}/{selected_continent}")
28
-
29
  if response.status_code == 200:
30
  data = response.json()
31
- print(data)
32
- st.write(data)
33
-
34
- # Display the continent information
35
- # st.header(f"Data of {data['continent']}")
36
- st.metric("Total Population", f"{data['total_population']:,}")
37
- st.metric("Total Area (sq km)", f"{data['total_area']:,}")
38
- st.metric("Population Density", f"{data['continent_population_density']:.2f}")
39
- st.subheader("Population Highlights")
40
- st.write(
41
- f"Max Population :{data['max_population']['country']} "
42
- f"({data['max_population']['population']:,})"
43
- )
44
- # Country with min population
45
- st.write(
46
- f"Min Population:{data['min_population']['country']} "
47
- f"({data['min_population']['population']:,})"
48
- )
49
  else:
50
- # Handle errors
51
  st.error(f"Error: {response.json()['detail']}")
52
 
 
 
1
  import streamlit as st
2
  import requests
 
3
 
4
+ # Set FastAPI backend URL
5
+ API_URL = "https://your-fastapi-space.hf.space" # Change to your actual FastAPI URL
 
 
 
 
 
 
6
 
7
+ # Streamlit UI
8
+ st.title("🌍 World Population Dashboard")
9
 
10
+ # Sidebar filter
11
  st.sidebar.header("Filter")
12
  selected_continent = st.sidebar.selectbox(
13
+ "Select a Continent:",
14
+ ["Asia", "Africa", "North America", "South America", "Europe", "Oceania"]
15
  )
16
 
 
17
  if st.sidebar.button("Get Data"):
18
+ # Call FastAPI
19
  response = requests.get(f"{API_URL}/{selected_continent}")
20
+
21
  if response.status_code == 200:
22
  data = response.json()
23
+
24
+ st.header(f"πŸ“Š {selected_continent} - Population Statistics")
25
+
26
+ # Display data in Streamlit
27
+ st.write(f"🟒 **Max Population:** {data['Max']}")
28
+ st.write(f"πŸ”΄ **Min Population:** {data['Min']}")
29
+ st.write(f"πŸ“‰ **Average Population:** {data['Avgerage']}")
30
+ st.write(f"🌎 **Total Area:** {data['Area']}")
31
+ st.write(f"πŸ‘₯ **Total Population:** {data['Sum']}")
32
+ st.write(f"πŸ— **Population Density:** {data['density']}")
33
+
 
 
 
 
 
 
 
34
  else:
 
35
  st.error(f"Error: {response.json()['detail']}")
36
 
37
+