import json from io import BytesIO from PIL import Image import os import streamlit as st import pandas as pd import numpy as np import torch import cv2 #from simple_detection import detect from one_image_detection import detect if 'img_list' not in st.session_state: st.session_state.img_list = [] st.title('Direct YoloV5 Inference') instructions = """ Upload your images and run the model to test the basic YoloV5 model. Check the original YoloV5 repository in: https://github.com/ultralytics/yolov5 """ st.write(instructions) if st.button('Run Model'): result = detect(st.session_state['img_list']) st.session_state['img_list'] = [] for image in result: image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) st.image(image, caption='Result') file = st.file_uploader('Upload An Image') if file: # if user uploaded file file_bytes = np.asarray(bytearray(file.read()), dtype=np.uint8) img = cv2.imdecode(file_bytes, 1) # print(len(img_list)) # img_list.append(img) # print("Loaded images = ") # print(len(img_list)) st.session_state['img_list'].append(img) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) st.title("Uploaded Image") resized_image = cv2.resize(img, (256,256)) st.image(resized_image)