Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,7 +22,11 @@ if upload_option == "Upload Image":
|
|
| 22 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
| 23 |
if uploaded_file is not None:
|
| 24 |
image = Image.open(uploaded_file)
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
st.image(results.render()[0], caption='Detected Objects', use_column_width=True)
|
| 27 |
|
| 28 |
# Real-Time Webcam Detection
|
|
@@ -45,7 +49,9 @@ if upload_option == "Real-Time Webcam":
|
|
| 45 |
|
| 46 |
# Convert to RGB and detect objects
|
| 47 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Render and display results
|
| 51 |
annotated_frame = results.render()[0]
|
|
|
|
| 22 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
| 23 |
if uploaded_file is not None:
|
| 24 |
image = Image.open(uploaded_file)
|
| 25 |
+
# Convert PIL image to numpy array
|
| 26 |
+
image_np = np.array(image)
|
| 27 |
+
# Convert numpy array to PyTorch tensor
|
| 28 |
+
image_tensor = torch.from_numpy(image_np)
|
| 29 |
+
results = model(image_tensor)
|
| 30 |
st.image(results.render()[0], caption='Detected Objects', use_column_width=True)
|
| 31 |
|
| 32 |
# Real-Time Webcam Detection
|
|
|
|
| 49 |
|
| 50 |
# Convert to RGB and detect objects
|
| 51 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 52 |
+
# Convert numpy array to PyTorch tensor
|
| 53 |
+
frame_tensor = torch.from_numpy(frame_rgb)
|
| 54 |
+
results = model(frame_tensor)
|
| 55 |
|
| 56 |
# Render and display results
|
| 57 |
annotated_frame = results.render()[0]
|