Spaces:
Build error
Build error
Commit ·
6091386
1
Parent(s): a289efe
Fycking tired of errors
Browse files
app.py
CHANGED
|
@@ -7,13 +7,12 @@ import streamlit as st
|
|
| 7 |
from PIL import Image
|
| 8 |
from huggingface_hub import hf_hub_download
|
| 9 |
|
| 10 |
-
# Configure Streamlit UI
|
| 11 |
-
st.title("Mosquito Detection from Camera Capture")
|
| 12 |
-
st.write("Take a picture to detect mosquito breeding sites using SSD.")
|
| 13 |
-
|
| 14 |
# Define dataset classes
|
| 15 |
classes = ['dengue-regions', 'wet_surface']
|
|
|
|
| 16 |
|
|
|
|
|
|
|
| 17 |
if 'model' not in st.session_state:
|
| 18 |
model_path = hf_hub_download(repo_id="DhominickJ/MosqScope", filename="mosquito_model.pth")
|
| 19 |
model = ssd300_vgg16(pretrained=True) # Multi-box Algorithm
|
|
@@ -21,6 +20,15 @@ if 'model' not in st.session_state:
|
|
| 21 |
model.eval()
|
| 22 |
st.session_state.model = model
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
captured_image = st.camera_input("Take a picture")
|
| 25 |
if captured_image is not None:
|
| 26 |
# Load image from Streamlit capture
|
|
@@ -31,7 +39,7 @@ if captured_image is not None:
|
|
| 31 |
image_np = np.array(image)
|
| 32 |
|
| 33 |
# Apply transformation for model input
|
| 34 |
-
image_tensor =
|
| 35 |
|
| 36 |
# Run inference
|
| 37 |
with torch.no_grad():
|
|
@@ -46,3 +54,5 @@ if captured_image is not None:
|
|
| 46 |
# Display frame in Streamlit
|
| 47 |
stframe.image(image_np, channels="RGB")
|
| 48 |
|
|
|
|
|
|
|
|
|
| 7 |
from PIL import Image
|
| 8 |
from huggingface_hub import hf_hub_download
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Define dataset classes
|
| 11 |
classes = ['dengue-regions', 'wet_surface']
|
| 12 |
+
num_classes = len(classes) + 1 # Including background
|
| 13 |
|
| 14 |
+
# Load Model
|
| 15 |
+
st.title("Real-Time SSD Object Detection")
|
| 16 |
if 'model' not in st.session_state:
|
| 17 |
model_path = hf_hub_download(repo_id="DhominickJ/MosqScope", filename="mosquito_model.pth")
|
| 18 |
model = ssd300_vgg16(pretrained=True) # Multi-box Algorithm
|
|
|
|
| 20 |
model.eval()
|
| 21 |
st.session_state.model = model
|
| 22 |
|
| 23 |
+
# Open webcam
|
| 24 |
+
cap = cv2.VideoCapture(0)
|
| 25 |
+
stframe = st.empty()
|
| 26 |
+
|
| 27 |
+
transform = transforms.Compose([
|
| 28 |
+
transforms.Resize((300, 300)),
|
| 29 |
+
transforms.ToTensor()
|
| 30 |
+
])
|
| 31 |
+
|
| 32 |
captured_image = st.camera_input("Take a picture")
|
| 33 |
if captured_image is not None:
|
| 34 |
# Load image from Streamlit capture
|
|
|
|
| 39 |
image_np = np.array(image)
|
| 40 |
|
| 41 |
# Apply transformation for model input
|
| 42 |
+
image_tensor = transform(image).unsqueeze(0)
|
| 43 |
|
| 44 |
# Run inference
|
| 45 |
with torch.no_grad():
|
|
|
|
| 54 |
# Display frame in Streamlit
|
| 55 |
stframe.image(image_np, channels="RGB")
|
| 56 |
|
| 57 |
+
cap.release()
|
| 58 |
+
cv2.destroyAllWindows()
|