Spaces:
Sleeping
Sleeping
Commit ·
b283eca
1
Parent(s): f71c745
update to old working one app.py
Browse files
app.py
CHANGED
|
@@ -2,30 +2,14 @@ import gradio as gr
|
|
| 2 |
import cv2
|
| 3 |
import os
|
| 4 |
import tempfile
|
| 5 |
-
import shutil
|
| 6 |
|
| 7 |
from ultralytics import YOLO
|
| 8 |
|
| 9 |
-
# Initialize YOLO model
|
| 10 |
-
model_path = r"best.pt"
|
| 11 |
-
if not os.path.exists(model_path):
|
| 12 |
-
raise FileNotFoundError(f"Model file not found at {model_path}")
|
| 13 |
-
model = YOLO(model_path)
|
| 14 |
-
|
| 15 |
-
# Define the maximum file size (100MB)
|
| 16 |
-
MAX_FILE_SIZE_MB = 70 # Limit is set to 100MB
|
| 17 |
-
MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024 # Convert MB to bytes
|
| 18 |
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
def process_video(video_file):
|
| 22 |
-
# Check the size of the uploaded video
|
| 23 |
-
video_size = os.path.getsize(video_file)
|
| 24 |
-
if video_size > MAX_FILE_SIZE_BYTES:
|
| 25 |
-
return f"Error: The uploaded video exceeds the 100MB size limit. Please upload a smaller video."
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
print("Video size is ", video_size/1024)
|
| 29 |
# Create a temporary folder to save extracted frames
|
| 30 |
temp_dir = tempfile.mkdtemp()
|
| 31 |
|
|
@@ -75,6 +59,7 @@ def process_video(video_file):
|
|
| 75 |
|
| 76 |
# Return the list of extracted frame paths for display
|
| 77 |
return extracted_frames
|
|
|
|
| 78 |
# Define the Gradio interface
|
| 79 |
iface = gr.Interface(
|
| 80 |
fn=process_video, # Function to process the video and return extracted frames
|
|
|
|
| 2 |
import cv2
|
| 3 |
import os
|
| 4 |
import tempfile
|
|
|
|
| 5 |
|
| 6 |
from ultralytics import YOLO
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
model = YOLO(r"best.pt") # initialize model
|
| 10 |
|
| 11 |
|
| 12 |
def process_video(video_file):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# Create a temporary folder to save extracted frames
|
| 14 |
temp_dir = tempfile.mkdtemp()
|
| 15 |
|
|
|
|
| 59 |
|
| 60 |
# Return the list of extracted frame paths for display
|
| 61 |
return extracted_frames
|
| 62 |
+
|
| 63 |
# Define the Gradio interface
|
| 64 |
iface = gr.Interface(
|
| 65 |
fn=process_video, # Function to process the video and return extracted frames
|