File size: 1,702 Bytes
a1a172c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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.")