Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,16 +12,17 @@ model_path = "best.pt"
|
|
12 |
if not os.path.exists(model_path):
|
13 |
os.system("wget https://huggingface.co/datasets/Prasanna1622/solar-fault-dataset/resolve/main/best.pt")
|
14 |
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
# Inference function
|
18 |
def detect_faults(video_path):
|
19 |
"""
|
20 |
- video_path: the path to the uploaded video file on disk.
|
21 |
- Returns: path to the annotated output.mp4.
|
22 |
"""
|
23 |
try:
|
24 |
-
# Create a unique RUN directory so YOLO does overwrite previous results
|
25 |
unique_id = str(uuid.uuid4())[:8]
|
26 |
project_dir = os.path.join("runs", "detect", unique_id)
|
27 |
os.makedirs(project_dir, exist_ok=True)
|
@@ -29,7 +30,7 @@ def detect_faults(video_path):
|
|
29 |
|
30 |
# Run YOLO predict; this saves the annotated video in project_dir/
|
31 |
results = model.predict(
|
32 |
-
source=video_path,
|
33 |
save=True,
|
34 |
save_txt=False,
|
35 |
conf=0.5,
|
@@ -38,8 +39,7 @@ def detect_faults(video_path):
|
|
38 |
)
|
39 |
print("✅ YOLO predict() finished.")
|
40 |
|
41 |
-
#
|
42 |
-
# annotated video is saved in runs/detect/<unique_id>/<original_filename>
|
43 |
original_name = os.path.basename(video_path)
|
44 |
output_video_path = os.path.join("runs", "detect", unique_id, original_name)
|
45 |
print(f"🛠️ Looking for output video at: {output_video_path}")
|
|
|
12 |
if not os.path.exists(model_path):
|
13 |
os.system("wget https://huggingface.co/datasets/Prasanna1622/solar-fault-dataset/resolve/main/best.pt")
|
14 |
|
15 |
+
# Initialize the YOLO model
|
16 |
+
model = YOLO(model_path)
|
17 |
|
18 |
+
# Inference function
|
|
|
19 |
def detect_faults(video_path):
|
20 |
"""
|
21 |
- video_path: the path to the uploaded video file on disk.
|
22 |
- Returns: path to the annotated output.mp4.
|
23 |
"""
|
24 |
try:
|
25 |
+
# Create a unique RUN directory so YOLO does not overwrite previous results
|
26 |
unique_id = str(uuid.uuid4())[:8]
|
27 |
project_dir = os.path.join("runs", "detect", unique_id)
|
28 |
os.makedirs(project_dir, exist_ok=True)
|
|
|
30 |
|
31 |
# Run YOLO predict; this saves the annotated video in project_dir/
|
32 |
results = model.predict(
|
33 |
+
source=video_path, # path to the uploaded video
|
34 |
save=True,
|
35 |
save_txt=False,
|
36 |
conf=0.5,
|
|
|
39 |
)
|
40 |
print("✅ YOLO predict() finished.")
|
41 |
|
42 |
+
# Check if output video exists
|
|
|
43 |
original_name = os.path.basename(video_path)
|
44 |
output_video_path = os.path.join("runs", "detect", unique_id, original_name)
|
45 |
print(f"🛠️ Looking for output video at: {output_video_path}")
|