Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import requests | |
| # Sidebar for user inputs | |
| st.sidebar.header("User Input Parameters") | |
| continent = st.sidebar.selectbox("Select Continent", ["Asia", "Africa", "Europe", "North America", "South America", "Oceania"]) | |
| data_type = st.sidebar.selectbox("Select Data Type", ["Population", "Area", "Density"]) | |
| stat = st.sidebar.selectbox("Select Statistic", ["max", "min", "mean", "sum", "count"]) | |
| # Function to compute statistics | |
| def get_statistics(continent, data_type, stat): | |
| url = f"http://127.0.0.1:8000/continents?continent={continent}&data_type={data_type}&stat={stat}" | |
| response = requests.get(url) | |
| if response.status_code == 200: | |
| return response.json() | |
| else: | |
| st.error(f"Error: {response.json().get('detail', 'Unknown error')}") | |
| return None | |
| # Display results | |
| if st.sidebar.button("Get Statistics"): | |
| result = get_statistics(continent, data_type, stat) | |
| if result: | |
| st.write(f"Result: {result['result']}") | |
| # Display continent info | |
| st.header("Continent Information") | |
| if st.button("Get Continent Info"): | |
| response = requests.get("http://127.0.0.1:8000/continent") | |
| if response.status_code == 200: | |
| continent_info = response.json() | |
| st.write(f"Number of Continents: {continent_info['number_of_continents']}") | |
| st.write("Continents:", continent_info['continents']) | |
| else: | |
| st.error("Failed to retrieve continent information.") | |
| # Display raw data | |
| st.header("Raw Data") | |
| if st.checkbox("Show raw data"): | |
| response = requests.get("http://127.0.0.1:8000/raw-data") | |
| if response.status_code == 200: | |
| st.write(response.json()) | |
| else: | |
| st.error("Failed to retrieve raw data.") |