message
Browse files
app.py
CHANGED
|
@@ -16,22 +16,28 @@ selected_continent = st.sidebar.selectbox(
|
|
| 16 |
|
| 17 |
if st.sidebar.button("Get Data"):
|
| 18 |
# Call FastAPI
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
st.header(f"π {selected_continent} - Population Statistics")
|
| 25 |
|
| 26 |
-
|
| 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
if st.sidebar.button("Get Data"):
|
| 18 |
# Call FastAPI
|
| 19 |
+
try:
|
| 20 |
+
response = requests.get(f"{API_URL}/{selected_continent}", timeout=10)
|
| 21 |
|
| 22 |
+
if response.status_code == 200:
|
| 23 |
+
try:
|
| 24 |
+
data = response.json() # Attempt to parse JSON
|
|
|
|
| 25 |
|
| 26 |
+
st.header(f"π {selected_continent} - Population Statistics")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# Display data in Streamlit
|
| 29 |
+
st.write(f"π’ **Max Population:** {data.get('Max', 'N/A')}")
|
| 30 |
+
st.write(f"π΄ **Min Population:** {data.get('Min', 'N/A')}")
|
| 31 |
+
st.write(f"π **Average Population:** {data.get('Average', 'N/A')}")
|
| 32 |
+
st.write(f"π **Total Area:** {data.get('Area', 'N/A')}")
|
| 33 |
+
st.write(f"π₯ **Total Population:** {data.get('Sum', 'N/A')}")
|
| 34 |
+
st.write(f"π **Population Density:** {data.get('density', 'N/A')}")
|
| 35 |
|
| 36 |
+
except requests.exceptions.JSONDecodeError:
|
| 37 |
+
st.error(f"Invalid JSON response received:\n{response.text}")
|
| 38 |
+
|
| 39 |
+
else:
|
| 40 |
+
st.error(f"API Error {response.status_code}: {response.text}")
|
| 41 |
+
|
| 42 |
+
except requests.exceptions.RequestException as e:
|
| 43 |
+
st.error(f"Request failed: {e}")
|