themalinery commited on
Commit
431b710
·
1 Parent(s): b0149cb

fix app.py

Browse files
Files changed (5) hide show
  1. .python-version +1 -1
  2. app.py +36 -34
  3. pyproject.toml +7 -7
  4. requirements.txt +0 -0
  5. uv.lock +0 -0
.python-version CHANGED
@@ -1 +1 @@
1
- 3.9
 
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
- raise gr.Error("Please enter at least one label")
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
- # Gradio interface
43
- with gr.Blocks(title="Video Object Detection", theme=gr.themes.Soft()) as demo:
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
- with gr.Column():
49
- video_input = gr.Video(label="Upload Video")
50
- labels_input = gr.Textbox(label="Detection Labels (comma-separated)", placeholder="e.g., cat, dog, person")
51
- color_input = gr.ColorPicker(label="Bounding Box Color", value="#FF0000")
52
- process_btn = gr.Button("Process Video", variant="primary")
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
- # Handle processing
63
- def process_and_update(video, labels_text, frame_color):
 
64
  try:
65
- # Update status
66
- gr.Info("Processing video... This may take a few minutes.")
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
- raise gr.Error(f"Processing failed: {str(e)}")
 
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.9"
7
  dependencies = [
 
8
  "accelerate>=1.10.1",
9
- "gradio>=4.0.0",
10
  "moviepy>=2.2.1",
11
  "natsort>=8.4.0",
12
- "opencv-python>=4.12.0.88",
13
- "pillow>=8.0,<11.0",
14
- "six>=1.17.0",
15
- "torch>=2.8.0",
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