Commit ·
8d70ec1
1
Parent(s): 7137256
Fixing file upload
Browse files- app.py +2 -2
- app_backend.py +22 -14
app.py
CHANGED
|
@@ -24,12 +24,12 @@ with gr.Blocks(title="Drone Crash Detection") as demo:
|
|
| 24 |
)
|
| 25 |
simulation_videos_upload = gr.File(
|
| 26 |
label="Upload Simulation Drone Videos",
|
| 27 |
-
type="
|
| 28 |
file_count="multiple"
|
| 29 |
)
|
| 30 |
real_videos_upload = gr.File(
|
| 31 |
label="Upload Real Drone Videos",
|
| 32 |
-
type="
|
| 33 |
file_count="multiple"
|
| 34 |
)
|
| 35 |
with gr.Row():
|
|
|
|
| 24 |
)
|
| 25 |
simulation_videos_upload = gr.File(
|
| 26 |
label="Upload Simulation Drone Videos",
|
| 27 |
+
type="filepath", # Changed 'file' to 'filepath'
|
| 28 |
file_count="multiple"
|
| 29 |
)
|
| 30 |
real_videos_upload = gr.File(
|
| 31 |
label="Upload Real Drone Videos",
|
| 32 |
+
type="filepath", # Changed 'file' to 'filepath'
|
| 33 |
file_count="multiple"
|
| 34 |
)
|
| 35 |
with gr.Row():
|
app_backend.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import csv
|
|
|
|
| 3 |
from dataclasses import dataclass
|
| 4 |
import model.video_classifier as classifier
|
| 5 |
|
|
@@ -8,6 +9,10 @@ model_path = './model/best.pt'
|
|
| 8 |
video_folder = './videos'
|
| 9 |
output_folder = './results'
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
model = classifier.get_model(model_path)
|
| 12 |
|
| 13 |
@dataclass
|
|
@@ -90,24 +95,27 @@ def backend(student_name_tb, simulation_files, real_files, frame_output, text_ou
|
|
| 90 |
simulation_paths = []
|
| 91 |
real_paths = []
|
| 92 |
|
| 93 |
-
#
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
simulation_paths.append(sim_video_path)
|
| 99 |
|
| 100 |
-
# Save the uploaded real videos to
|
| 101 |
-
for i,
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
real_paths.append(real_video_path)
|
| 106 |
|
| 107 |
-
# Store original filenames
|
| 108 |
-
simulation_filenames = [file.name for file in simulation_files]
|
| 109 |
-
real_filenames = [file.name for file in real_files]
|
| 110 |
-
|
| 111 |
simulation_results = []
|
| 112 |
real_results = []
|
| 113 |
output_video_paths = []
|
|
|
|
| 1 |
import os
|
| 2 |
import csv
|
| 3 |
+
import shutil # Added to copy files
|
| 4 |
from dataclasses import dataclass
|
| 5 |
import model.video_classifier as classifier
|
| 6 |
|
|
|
|
| 9 |
video_folder = './videos'
|
| 10 |
output_folder = './results'
|
| 11 |
|
| 12 |
+
# Ensure the directories exist
|
| 13 |
+
os.makedirs(video_folder, exist_ok=True)
|
| 14 |
+
os.makedirs(output_folder, exist_ok=True)
|
| 15 |
+
|
| 16 |
model = classifier.get_model(model_path)
|
| 17 |
|
| 18 |
@dataclass
|
|
|
|
| 95 |
simulation_paths = []
|
| 96 |
real_paths = []
|
| 97 |
|
| 98 |
+
# Ensure the video_folder exists
|
| 99 |
+
os.makedirs(video_folder, exist_ok=True)
|
| 100 |
+
|
| 101 |
+
# Store original filenames
|
| 102 |
+
simulation_filenames = [os.path.basename(file_path) for file_path in simulation_files]
|
| 103 |
+
real_filenames = [os.path.basename(file_path) for file_path in real_files]
|
| 104 |
+
|
| 105 |
+
# Save the uploaded simulation videos to the 'video_folder'
|
| 106 |
+
for i, file_path in enumerate(simulation_files, start=1):
|
| 107 |
+
ext = os.path.splitext(file_path)[1]
|
| 108 |
+
sim_video_path = os.path.join(video_folder, f'sim_video{i}{ext}')
|
| 109 |
+
shutil.copy(file_path, sim_video_path)
|
| 110 |
simulation_paths.append(sim_video_path)
|
| 111 |
|
| 112 |
+
# Save the uploaded real videos to the 'video_folder'
|
| 113 |
+
for i, file_path in enumerate(real_files, start=1):
|
| 114 |
+
ext = os.path.splitext(file_path)[1]
|
| 115 |
+
real_video_path = os.path.join(video_folder, f'real_video{i}{ext}')
|
| 116 |
+
shutil.copy(file_path, real_video_path)
|
| 117 |
real_paths.append(real_video_path)
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
simulation_results = []
|
| 120 |
real_results = []
|
| 121 |
output_video_paths = []
|