Spaces:
Running
Running
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,131 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import keras
|
| 3 |
-
import numpy as np
|
| 4 |
-
from PIL import Image
|
| 5 |
-
import io
|
| 6 |
-
import urllib.request
|
| 7 |
-
import os
|
| 8 |
-
st.set_page_config(layout="wide")
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
st.markdown("""
|
| 12 |
-
<style>
|
| 13 |
-
.block-container {
|
| 14 |
-
padding-top: 1rem;
|
| 15 |
-
padding-bottom: 0rem;
|
| 16 |
-
padding-left: 5rem;
|
| 17 |
-
padding-right: 5rem;
|
| 18 |
-
}
|
| 19 |
-
</style>
|
| 20 |
-
""", unsafe_allow_html=True)
|
| 21 |
-
|
| 22 |
-
#title
|
| 23 |
-
col1, col2 = st.columns(2)
|
| 24 |
-
with col1:
|
| 25 |
-
buffer, col = st.columns(2)
|
| 26 |
-
with col:
|
| 27 |
-
st.header('Overpass Identifier')
|
| 28 |
-
with col2:
|
| 29 |
-
buffer1, col, buffer2 = st.columns(3)
|
| 30 |
-
with col:
|
| 31 |
-
st.image('overpass.png')
|
| 32 |
-
|
| 33 |
-
st.write("---")
|
| 34 |
-
|
| 35 |
-
#load model and initialize image size required by model. uploaded images are resized to indicated size
|
| 36 |
-
img_height = 640
|
| 37 |
-
img_width = 640
|
| 38 |
-
|
| 39 |
-
state = st.session_state
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
if "loaded_model" not in state:
|
| 43 |
-
with st.spinner('Loading model. This may take a few seconds...'):
|
| 44 |
-
state.loaded_model = keras.models.load_model("0.0008-0.92.keras")
|
| 45 |
-
|
| 46 |
-
if "lat" not in state:
|
| 47 |
-
state.lat = 39.11
|
| 48 |
-
|
| 49 |
-
if "lng" not in state:
|
| 50 |
-
state.lng = -86.56
|
| 51 |
-
|
| 52 |
-
if "coords_submitted" not in state:
|
| 53 |
-
state.coords_submitted = False
|
| 54 |
-
|
| 55 |
-
#if "img_submitted" not in state:
|
| 56 |
-
#state.img_submitted = False
|
| 57 |
-
|
| 58 |
-
if "img" not in state:
|
| 59 |
-
state.img = None
|
| 60 |
-
|
| 61 |
-
col1, col2, col3 = st.columns(3)
|
| 62 |
-
with col3:
|
| 63 |
-
#header
|
| 64 |
-
st.subheader('Enter latitude/longitude coordinates:')
|
| 65 |
-
|
| 66 |
-
coll, colr= st.columns(2)
|
| 67 |
-
with coll:
|
| 68 |
-
state.lat = st.number_input('Latitude', value=39.11, min_value=-90., max_value=90., step=.01)
|
| 69 |
-
st.write('The current lat/long are:')
|
| 70 |
-
with colr:
|
| 71 |
-
state.lng = st.number_input('Longitude', value=-86.56, min_value=-180., max_value=180., step=.01)
|
| 72 |
-
st.write(str(state.lat)+', '+str(state.lng))
|
| 73 |
-
with st.form("my_form"):
|
| 74 |
-
submit_button = st.form_submit_button(
|
| 75 |
-
label="Get Image and Prediction", on_click=lambda: state.update(coords_submitted=True))
|
| 76 |
-
#header
|
| 77 |
-
#st.subheader('Upload a satellite image:')
|
| 78 |
-
#img_buffer = st.file_uploader("Upload a satellite image file (format: .png, .jpeg, or .jpg).",type=['png', 'jpeg', 'jpg'])
|
| 79 |
-
#if img_buffer is not None:
|
| 80 |
-
#state.img = Image.open(img_buffer).convert("RGB")
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
with col2:
|
| 84 |
-
if state.coords_submitted:
|
| 85 |
-
state.coords_submitted = False
|
| 86 |
-
try:
|
| 87 |
-
api_key = os.getenv("goog_api")
|
| 88 |
-
url = "https://maps.googleapis.com/maps/api/staticmap?center="+str(state.lat)+","+str(state.lng)+"&zoom=16&size=640x640&maptype=satellite&key="+api_key
|
| 89 |
-
buffer = io.BytesIO(urllib.request.urlopen(url).read())
|
| 90 |
-
state.img = Image.open(buffer).convert("RGB")
|
| 91 |
-
except Exception as e:
|
| 92 |
-
st.write("Error! Could not access Google Static API. Error code:",e)
|
| 93 |
-
if state.img is not None:
|
| 94 |
-
st.image(state.img, use_column_width = True)
|
| 95 |
-
|
| 96 |
-
with col1:
|
| 97 |
-
st.subheader("Prediction")
|
| 98 |
-
if state.img is not None:
|
| 99 |
-
img_array = np.array(state.img)
|
| 100 |
-
batch_size = 1
|
| 101 |
-
img_array = np.reshape(img_array,[batch_size,img_height,img_width,3])
|
| 102 |
-
result = state.loaded_model.predict(img_array)
|
| 103 |
-
crossing_chance = result[0][1]*100
|
| 104 |
-
status = None
|
| 105 |
-
while status is None:
|
| 106 |
-
if crossing_chance >= 0:
|
| 107 |
-
status = "extremely un"
|
| 108 |
-
if crossing_chance >= 10:
|
| 109 |
-
status = "highly un"
|
| 110 |
-
if crossing_chance >= 20:
|
| 111 |
-
status = "pretty un"
|
| 112 |
-
if crossing_chance >= 30:
|
| 113 |
-
status = "slightly un"
|
| 114 |
-
if crossing_chance >= 40:
|
| 115 |
-
status = "a tiny bit more unlikely than "
|
| 116 |
-
if crossing_chance >= 50:
|
| 117 |
-
status = "a tiny bit more likely than un"
|
| 118 |
-
if crossing_chance >= 60:
|
| 119 |
-
status = "slightly "
|
| 120 |
-
if crossing_chance >= 70:
|
| 121 |
-
status = "pretty "
|
| 122 |
-
if crossing_chance >= 80:
|
| 123 |
-
status = "highly "
|
| 124 |
-
if crossing_chance >= 90:
|
| 125 |
-
status = "extremely "
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
st.write(f"It's {status}likely there's at least one overpass here.")
|
| 129 |
-
st.write("")
|
| 130 |
-
st.write(f"In fact, the likelihood of at least one overpass is {np.round(crossing_chance,decimals=2)}%.")
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|