Chittrarasu commited on
Commit
c904db4
·
1 Parent(s): 88721c8

added streamlit

Browse files
Files changed (1) hide show
  1. population_streamlit.py +81 -0
population_streamlit.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import streamlit as st
2
+ # import requests
3
+
4
+ # BASE_URL = "http://127.0.0.1:8000" # Update with your FastAPI server URL
5
+
6
+ # st.title("World Population")
7
+
8
+ # # Fetch all continents
9
+ # response = requests.get(f"{BASE_URL}/continents/")
10
+ # if response.status_code == 200:
11
+ # continents = response.json()["continents"]
12
+ # else:
13
+ # st.error("Failed to fetch continents")
14
+ # continents = []
15
+
16
+ # selected_continent = st.selectbox("Select a continent:", continents)
17
+
18
+ # if selected_continent:
19
+ # stat = st.text_input("Enter a statistic to fetch (optional):")
20
+
21
+ # url = f"{BASE_URL}/continents/{selected_continent}/"
22
+ # if stat:
23
+ # url += f"?stat={stat}"
24
+
25
+ # response = requests.get(url)
26
+ # if response.status_code == 200:
27
+ # data = response.json()
28
+ # st.json(data)
29
+ # else:
30
+ # st.error("Failed to fetch data")
31
+
32
+ #DEEPSEEK
33
+
34
+ import streamlit as st
35
+ import requests
36
+
37
+ # FastAPI backend URL
38
+ FASTAPI_URL = "http://127.0.0.1:8000"
39
+
40
+ # Streamlit app
41
+ # def main():
42
+ st.title("World Population Statistics")
43
+
44
+ # Fetch all continents
45
+ response = requests.get(f"{FASTAPI_URL}/continents/")
46
+ if response.status_code == 200:
47
+ continents = response.json()["continents"]
48
+ else:
49
+ st.error("Failed to fetch continents")
50
+
51
+
52
+ # Dropdown to select a continent
53
+ selected_continent = st.selectbox("Select a Continent", continents)
54
+
55
+ # Fetch statistics for the selected continent
56
+ response = requests.get(f"{FASTAPI_URL}/continents/{selected_continent}/")
57
+ if response.status_code == 200:
58
+ continent_stats = response.json()
59
+ else:
60
+ st.error(f"Failed to fetch statistics for {selected_continent}")
61
+
62
+
63
+ # Display the statistics
64
+ st.subheader(f"Statistics for {selected_continent}")
65
+ st.write(f"**Total Countries:** {continent_stats['Total_Countries']}")
66
+ st.write(f"**Total Population:** {continent_stats['Total_Population']}")
67
+ st.write(f"**Average Population:** {continent_stats['Average_Population']}")
68
+ st.write(f"**Total Area:** {continent_stats['Total_Area']}")
69
+ st.write(f"**Max Population:** {continent_stats['max_population']}")
70
+ st.write(f"**Min Population:** {continent_stats['min_population']}")
71
+ st.write(f"**Country with Max Population:** {continent_stats['Country_Max_Population']}")
72
+ st.write(f"**Country with Min Population:** {continent_stats['Country_Min_Population']}")
73
+ st.write(f"**Population Density:** {continent_stats['Population_Density']}")
74
+
75
+ # Option to view a specific statistic
76
+ stat_options = list(continent_stats.keys())
77
+ selected_stat = st.selectbox("Select a specific statistic to view", stat_options)
78
+ st.write(f"**{selected_stat}:** {continent_stats[selected_stat]}")
79
+
80
+ # if __name__ == "__main__":
81
+ # main()