Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,13 +8,18 @@ from gtts import gTTS
|
|
8 |
import threading
|
9 |
from datetime import datetime, timedelta
|
10 |
|
11 |
-
#
|
12 |
running_in_cloud = "HF_HOME" in os.environ
|
13 |
|
14 |
if not running_in_cloud:
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
# Load YOLOv8 model
|
20 |
yolo = YOLO("yolov8n.pt")
|
@@ -190,4 +195,4 @@ if start_detection:
|
|
190 |
pygame.mixer.quit()
|
191 |
|
192 |
elif stop_detection:
|
193 |
-
st.warning("Object detection stopped.")
|
|
|
8 |
import threading
|
9 |
from datetime import datetime, timedelta
|
10 |
|
11 |
+
# Detect if running in a cloud environment (e.g., Hugging Face Spaces)
|
12 |
running_in_cloud = "HF_HOME" in os.environ
|
13 |
|
14 |
if not running_in_cloud:
|
15 |
+
try:
|
16 |
+
import pygame
|
17 |
+
pygame.mixer.quit() # Ensure the mixer is fully stopped
|
18 |
+
pygame.mixer.init()
|
19 |
+
except ImportError:
|
20 |
+
print("pygame module not found, skipping audio initialization.")
|
21 |
+
else:
|
22 |
+
print("Running in cloud mode: Skipping pygame initialization.")
|
23 |
|
24 |
# Load YOLOv8 model
|
25 |
yolo = YOLO("yolov8n.pt")
|
|
|
195 |
pygame.mixer.quit()
|
196 |
|
197 |
elif stop_detection:
|
198 |
+
st.warning("Object detection stopped.")
|