File size: 4,328 Bytes
bcc0b1d
 
 
 
 
 
73cf8d9
bcc0b1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df62ecf
bcc0b1d
 
 
 
 
 
 
 
 
1c638fb
bcc0b1d
1c638fb
d81c920
bcc0b1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df6ee5c
73cf8d9
bcc0b1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import streamlit as st
import keras
import numpy as np
from PIL import Image
import io
import urllib.request
import os
st.set_page_config(layout="wide")


st.markdown("""
        <style>
               .block-container {
                    padding-top: 1rem;
                    padding-bottom: 0rem;
                    padding-left: 5rem;
                    padding-right: 5rem;
                }
        </style>
        """, unsafe_allow_html=True)

#title
col1, col2 = st.columns(2)
with col1:
    buffer, col = st.columns(2)
    with col:
        st.header('Overpass Identifier')
with col2:
    buffer1, col, buffer2 = st.columns(3)
    with col:
        st.image('overpass.png')

st.write("---")

#load model and initialize image size required by model. uploaded images are resized to indicated size
img_height = 640
img_width = 640

state = st.session_state


if "loaded_model" not in state:
    with st.spinner('Loading model. This may take a few seconds...'):
        state.loaded_model = keras.models.load_model("0.0008-0.92.keras")

if "lat" not in state:
    state.lat = 39.11

if "lng" not in state:
    state.lng = -86.56 

if "coords_submitted" not in state:
    state.coords_submitted = False

#if "img_submitted" not in state:
    #state.img_submitted = False

if "img" not in state:
    state.img = None

col1, col2, col3 = st.columns(3)
with col3:
    #header
    st.subheader('Enter latitude/longitude coordinates:') 
                 
    coll, colr= st.columns(2)
    with coll:
        state.lat = st.number_input('Latitude', value=39.11, min_value=-90., max_value=90., step=.01) 
        st.write('The current lat/long are:')     
    with colr:        
        state.lng = st.number_input('Longitude', value=-86.56, min_value=-180., max_value=180., step=.01) 
        st.write(str(state.lat)+', '+str(state.lng))      
        with st.form("my_form"):
            submit_button = st.form_submit_button(
            label="Get Image and Prediction", on_click=lambda: state.update(coords_submitted=True))
        #header
    #st.subheader('Upload a satellite image:') 
    #img_buffer = st.file_uploader("Upload a satellite image file (format: .png, .jpeg, or .jpg).",type=['png', 'jpeg', 'jpg'])
    #if img_buffer is not None:
        #state.img = Image.open(img_buffer).convert("RGB")
    

with col2:
    if state.coords_submitted:
        state.coords_submitted = False
        try:
            api_key = os.getenv("goog_api")
            url = "https://maps.googleapis.com/maps/api/staticmap?center="+str(state.lat)+","+str(state.lng)+"&zoom=16&size=640x640&maptype=satellite&key="+api_key
            buffer = io.BytesIO(urllib.request.urlopen(url).read())
            state.img = Image.open(buffer).convert("RGB")     
        except Exception as e:
            st.write("Error! Could not access Google Static API. Error code:",e)
        if state.img is not None:
            st.image(state.img, use_column_width = True)

with col1:
    st.subheader("Prediction")
    if state.img is not None:
        img_array = np.array(state.img)
        batch_size = 1
        img_array = np.reshape(img_array,[batch_size,img_height,img_width,3])
        result = state.loaded_model.predict(img_array)
        crossing_chance = result[0][1]*100
        status = None
        while status is None:
            if crossing_chance >= 0:
                status = "extremely un"
            if crossing_chance >= 10:
                status = "highly un"
            if crossing_chance >= 20:
                status = "pretty un"
            if crossing_chance >= 30:
                status = "slightly un"
            if crossing_chance >= 40:
                status = "a tiny bit more unlikely than "
            if crossing_chance >= 50:
                status = "a tiny bit more likely than un"
            if crossing_chance >= 60:
                status = "slightly "
            if crossing_chance >= 70:
                status = "pretty "
            if crossing_chance >= 80:
                status = "highly "
            if crossing_chance >= 90:
                status = "extremely "


        st.write(f"It's {status}likely there's at least one overpass here.")
        st.write("")
        st.write(f"In fact, the likelihood of at least one overpass is {np.round(crossing_chance,decimals=2)}%.")