Spaces:
Runtime error
Runtime error
File size: 1,943 Bytes
630886e |
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 |
"""Streamlit web app for depth of field detection"""
import time
from PIL import Image
import streamlit as st
from bokeh import app_dof_predict
from tempfile import NamedTemporaryFile
temp_file = NamedTemporaryFile(delete=False)
# Page layout
st.set_page_config(page_title="Depth of Field Detection", page_icon=":camera:", layout="wide")
# Sidebar options
st.sidebar.title("Prediction Settings")
st.sidebar.text("")
models = ["DenseNet (baseline)", "VGG16 (baseline)", "DenseNet (best)", "VGG16 (best)"]
model_choice = []
st.sidebar.write("Choose a model for prediction")
model_choice.append(st.sidebar.radio("", models))
with st.container():
st.title("Depth of Field detection w/ Deep Learning")
st.image(
"https://source.unsplash.com/FABH5NJEMGM/960x640",
use_column_width="auto",
)
file = st.file_uploader("Upload an image", type=["jpg", "jpeg"])
if file is not None:
img = Image.open(file)
temp_file.write(file.getvalue())
st.image(img, caption="Uploaded image", use_column_width="auto")
if st.button("Predict"):
st.write("")
st.write("Working...")
start_time = time.time()
for choice in model_choice:
prediction = app_dof_predict(choice, temp_file.name)
print(prediction)
execute_bar = st.progress(0)
for percent_complete in range(100):
time.sleep(0.001)
execute_bar.progress(percent_complete + 1)
prob = prediction["probability"]
if prediction["class"] == 0:
st.header("Prediction: Bokeh - Confidence {:.1f}%".format(prob * 100))
elif prediction["class"] == 1:
st.header("Prediction: No bokeh detected - Confidence {:.1f}%".format(prob * 100))
st.write("Took {} seconds to run.".format(round(time.time() - start_time, 2)))
|