Spaces:
Sleeping
Sleeping
Commit ·
431b710
1
Parent(s): b0149cb
fix app.py
Browse files- .python-version +1 -1
- app.py +36 -34
- pyproject.toml +7 -7
- requirements.txt +0 -0
- uv.lock +0 -0
.python-version
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
3.
|
|
|
|
| 1 |
+
3.10
|
app.py
CHANGED
|
@@ -2,6 +2,24 @@ import gradio as gr
|
|
| 2 |
import tempfile
|
| 3 |
import shutil
|
| 4 |
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
from src.utils import create_video_from_images, object_detection
|
| 7 |
|
|
@@ -10,7 +28,7 @@ def process_video(video_file, labels_text, frame_color):
|
|
| 10 |
text_labels = [label.strip() for label in labels_text.split(',') if label.strip()]
|
| 11 |
|
| 12 |
if not text_labels:
|
| 13 |
-
|
| 14 |
|
| 15 |
# Create config
|
| 16 |
config = {
|
|
@@ -39,45 +57,29 @@ def process_video(video_file, labels_text, frame_color):
|
|
| 39 |
|
| 40 |
return str(final_output)
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
with gr.Blocks(
|
| 44 |
gr.Markdown("# Video Object Detection")
|
| 45 |
-
gr.Markdown("Upload a video, enter labels to detect, choose frame color, and download the processed video.")
|
| 46 |
|
| 47 |
with gr.Row():
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
with gr.Column():
|
| 55 |
-
# Output section
|
| 56 |
-
gr.Markdown("## Output")
|
| 57 |
-
|
| 58 |
-
output_video = gr.Video(label="Processed Video", interactive=False)
|
| 59 |
-
|
| 60 |
-
download_button = gr.File(label="Download Processed Video", visible=False)
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
|
|
|
| 64 |
try:
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
output_path = process_video(video, labels_text, frame_color)
|
| 69 |
-
|
| 70 |
-
gr.Info("Video processing complete!")
|
| 71 |
-
|
| 72 |
-
return output_path, output_path
|
| 73 |
except Exception as e:
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
-
process_btn.click(
|
| 77 |
-
fn=process_and_update,
|
| 78 |
-
inputs=[video_input, labels_input, color_input],
|
| 79 |
-
outputs=[output_video, download_button]
|
| 80 |
-
)
|
| 81 |
|
| 82 |
if __name__ == "__main__":
|
| 83 |
-
demo.launch()
|
|
|
|
| 2 |
import tempfile
|
| 3 |
import shutil
|
| 4 |
from pathlib import Path
|
| 5 |
+
import sys
|
| 6 |
+
|
| 7 |
+
# Monkey patch to fix gradio_client schema parsing bug
|
| 8 |
+
try:
|
| 9 |
+
from gradio_client import utils as client_utils
|
| 10 |
+
|
| 11 |
+
# Patch the main function that fails when encountering booleans
|
| 12 |
+
original_json_schema_to_python_type = client_utils._json_schema_to_python_type
|
| 13 |
+
|
| 14 |
+
def patched_json_schema_to_python_type(schema, defs=None):
|
| 15 |
+
# If schema is a boolean, return a simple dict representation
|
| 16 |
+
if isinstance(schema, bool):
|
| 17 |
+
return "bool"
|
| 18 |
+
return original_json_schema_to_python_type(schema, defs)
|
| 19 |
+
|
| 20 |
+
client_utils._json_schema_to_python_type = patched_json_schema_to_python_type
|
| 21 |
+
except Exception as e:
|
| 22 |
+
print(f"Warning: Could not apply monkey patch: {e}")
|
| 23 |
|
| 24 |
from src.utils import create_video_from_images, object_detection
|
| 25 |
|
|
|
|
| 28 |
text_labels = [label.strip() for label in labels_text.split(',') if label.strip()]
|
| 29 |
|
| 30 |
if not text_labels:
|
| 31 |
+
return None
|
| 32 |
|
| 33 |
# Create config
|
| 34 |
config = {
|
|
|
|
| 57 |
|
| 58 |
return str(final_output)
|
| 59 |
|
| 60 |
+
# Simple gradio interface
|
| 61 |
+
with gr.Blocks() as demo:
|
| 62 |
gr.Markdown("# Video Object Detection")
|
|
|
|
| 63 |
|
| 64 |
with gr.Row():
|
| 65 |
+
video_input = gr.File(label="Upload Video", file_types=[".mp4", ".avi", ".mov"])
|
| 66 |
+
labels_input = gr.Textbox(label="Labels (comma-separated)", placeholder="cat,dog,person")
|
| 67 |
+
color_input = gr.ColorPicker(label="Bounding Box Color", value="#FF0000")
|
| 68 |
+
|
| 69 |
+
process_btn = gr.Button("Process")
|
| 70 |
+
output = gr.File(label="Download")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
+
def process(video, labels, color):
|
| 73 |
+
if not video or not labels:
|
| 74 |
+
return None
|
| 75 |
try:
|
| 76 |
+
result = process_video(video, labels, color)
|
| 77 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
except Exception as e:
|
| 79 |
+
print(f"Error: {e}")
|
| 80 |
+
return None
|
| 81 |
|
| 82 |
+
process_btn.click(process, inputs=[video_input, labels_input, color_input], outputs=output)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
if __name__ == "__main__":
|
| 85 |
+
demo.launch(share=True)
|
pyproject.toml
CHANGED
|
@@ -3,15 +3,15 @@ name = "object-detection"
|
|
| 3 |
version = "0.1.0"
|
| 4 |
description = "Add your description here"
|
| 5 |
readme = "README.md"
|
| 6 |
-
requires-python = ">=3.
|
| 7 |
dependencies = [
|
|
|
|
| 8 |
"accelerate>=1.10.1",
|
| 9 |
-
"gradio
|
| 10 |
"moviepy>=2.2.1",
|
| 11 |
"natsort>=8.4.0",
|
| 12 |
-
"opencv-python
|
| 13 |
-
"pillow>=
|
| 14 |
-
"
|
| 15 |
-
"
|
| 16 |
-
"transformers>=4.57.1",
|
| 17 |
]
|
|
|
|
| 3 |
version = "0.1.0"
|
| 4 |
description = "Add your description here"
|
| 5 |
readme = "README.md"
|
| 6 |
+
requires-python = ">=3.10"
|
| 7 |
dependencies = [
|
| 8 |
+
"absl-py>=1.0.0",
|
| 9 |
"accelerate>=1.10.1",
|
| 10 |
+
"gradio==4.41.0",
|
| 11 |
"moviepy>=2.2.1",
|
| 12 |
"natsort>=8.4.0",
|
| 13 |
+
"opencv-python==4.11.0.86",
|
| 14 |
+
"pillow>=10.0,<11.0",
|
| 15 |
+
"torch>=2.4.0",
|
| 16 |
+
"transformers>=4.41.0",
|
|
|
|
| 17 |
]
|
requirements.txt
CHANGED
|
Binary files a/requirements.txt and b/requirements.txt differ
|
|
|
uv.lock
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|