Spaces:
Runtime error
Runtime error
File size: 2,717 Bytes
2fdba78 f977726 2fdba78 f977726 2fdba78 f977726 2fdba78 201909f f977726 e40afe0 f977726 e40afe0 f977726 2fdba78 f977726 2fdba78 f977726 2fdba78 f977726 2fdba78 f977726 ec500f1 |
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 |
import contextlib
import time
from functools import wraps
from io import StringIO
from zipfile import ZipFile
import streamlit as st
from PIL import Image
import evaluator
from yolo_dataset import YoloDataset
from yolo_fire import detect
def main():
# Header & Page Config.
st.set_page_config(
page_title="Fire&Smoke Detection",
layout="centered")
st.title("Fire&Smoke Detection:")
detect_tab, evaluate_tab = st.tabs(["Detect", "Evaluate"])
with evaluate_tab:
buffer = st.file_uploader("Upload your Yolo Dataset here", type=["zip"])
if buffer:
with st.spinner('Wait for it...'):
# Slider for changing confidence
confidence = st.slider('Confidence Threshold', 0, 100, 30)
yolo_dataset = YoloDataset.from_zip_file(ZipFile(buffer))
capture_output(evaluator.evaluate)(coco_gt=yolo_dataset.to_coco(), loader=yolo_dataset.load_image,
confidence_threshold=confidence / 100.0)
with detect_tab:
# This will let you upload PNG, JPG & JPEG File
buffer = st.file_uploader("Upload your Image here", type=["jpg", "png", "jpeg"])
if buffer:
# Object Detecting
with st.spinner('Wait for it...'):
# Slider for changing confidence
confidence = st.slider('Confidence Threshold', 0, 100, 30)
# Calculating time for detection
t1 = time.time()
im = Image.open(buffer)
# im.save("saved_images/image.jpg")
res_img = detect(im, confidence / 100.0)
t2 = time.time()
# Displaying the image
st.image(res_img, use_column_width=True)
# Printing Time
st.write("\n")
st.write("Time taken: ", t2 - t1, "sec.")
def capture_output(func):
"""Capture output from running a function and write using streamlit."""
@wraps(func)
def wrapper(*args, **kwargs):
# Redirect output to string buffers
stdout, stderr = StringIO(), StringIO()
try:
with contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(stderr):
return func(*args, **kwargs)
except Exception as err:
st.write(f"Failure while executing: {err}")
finally:
if _stdout := stdout.getvalue():
st.write("Execution stdout:")
st.code(_stdout)
if _stderr := stderr.getvalue():
st.write("Execution stderr:")
st.code(_stderr)
return wrapper
if __name__ == '__main__':
main()
|