|
|
|
|
|
import gradio as gr |
|
import os |
|
|
|
from Fight_detec_func import fight_detec |
|
from objec_detect_yolo import detection |
|
import traceback |
|
|
|
def analyze_video(video_filepath): |
|
if video_filepath is None: |
|
return {"Error": "No video file uploaded."} |
|
|
|
|
|
print(f"Processing video: {video_filepath}") |
|
|
|
try: |
|
|
|
|
|
fight_status, _ = fight_detec(video_filepath, debug=False) |
|
detected_objects_set, annotated_video_path = detection(video_filepath) |
|
|
|
|
|
detected_objects_list = sorted(list(detected_objects_set)) |
|
|
|
print(f"Fight Status: {fight_status}") |
|
print(f"Detected Objects: {detected_objects_list}") |
|
|
|
|
|
|
|
|
|
results = { |
|
"Fight Detection": fight_status, |
|
"Detected Objects": detected_objects_list |
|
} |
|
|
|
except Exception as e: |
|
print(f"Error during processing video: {video_filepath}") |
|
print(f"Error type: {type(e).__name__}") |
|
print(f"Error message: {e}") |
|
print("Traceback:") |
|
traceback.print_exc() |
|
results = {"Error": f"Processing failed. Check Space logs for details. Error: {str(e)}"} |
|
|
|
|
|
|
|
|
|
|
|
return results |
|
|
|
|
|
iface = gr.Interface( |
|
fn=analyze_video, |
|
inputs=gr.Video(label="Upload Video"), |
|
outputs=gr.JSON(label="Detection Results"), |
|
title="Fight and Object Detection Analysis", |
|
description="Upload a video (< 1 min recommended) to detect potential fights and specific objects (Fire, Gun, Knife, Smoke, License_Plate). Results appear as JSON.", |
|
allow_flagging='never', |
|
examples=[ |
|
|
|
|
|
] |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|
|
|