Spaces:
Sleeping
Sleeping
smellslikeml
commited on
Commit
·
26cfda6
1
Parent(s):
e831eb1
adding video_crop_tool
Browse files- README.md +2 -2
- app.py +4 -0
- requirements.txt +3 -0
- tool_config.json +6 -0
- video_crop.py +30 -0
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
title: Video Crop Tool
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: green
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.33.1
|
| 8 |
app_file: app.py
|
|
|
|
| 1 |
---
|
| 2 |
title: Video Crop Tool
|
| 3 |
+
emoji: ✂️
|
| 4 |
colorFrom: green
|
| 5 |
+
colorTo: orange
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.33.1
|
| 8 |
app_file: app.py
|
app.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers.tools.base import launch_gradio_demo
|
| 2 |
+
from video_crop import VideoCropTool
|
| 3 |
+
|
| 4 |
+
launch_gradio_demo(VideoCropTool)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ffmpeg-python
|
| 2 |
+
huggingface_hub
|
| 3 |
+
transformers
|
tool_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"description": "This tool crops a video with inputs: input_path, output_path, top_x, top_y, bottom_x, bottom_y. Output is the output_path.",
|
| 3 |
+
"name": "video_crop_tool",
|
| 4 |
+
"tool_class": "video_crop.VideoCropTool"
|
| 5 |
+
}
|
| 6 |
+
|
video_crop.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import ffmpeg
|
| 3 |
+
from transformers import Tool
|
| 4 |
+
|
| 5 |
+
class VideoCropTool(Tool):
|
| 6 |
+
name = "video_crop_tool"
|
| 7 |
+
description = """
|
| 8 |
+
This tool crops a video with inputs:
|
| 9 |
+
input_path, output_path,
|
| 10 |
+
top_x, top_y,
|
| 11 |
+
bottom_x, bottom_y.
|
| 12 |
+
Output is the output_path.
|
| 13 |
+
"""
|
| 14 |
+
inputs = ["text", "text", "text", "text", "text", "text"]
|
| 15 |
+
outputs = ["text"]
|
| 16 |
+
|
| 17 |
+
def __call__(
|
| 18 |
+
self,
|
| 19 |
+
input_path: str,
|
| 20 |
+
output_path: str,
|
| 21 |
+
top_x: str,
|
| 22 |
+
top_y: str,
|
| 23 |
+
bottom_x: str,
|
| 24 |
+
bottom_y: str,
|
| 25 |
+
):
|
| 26 |
+
stream = ffmpeg.input(input_path)
|
| 27 |
+
stream = ffmpeg.crop(stream, int(top_y), int(top_x), int(bottom_y) - int(top_y), int(bottom_x) - int(top_x))
|
| 28 |
+
stream = ffmpeg.output(stream, output_path)
|
| 29 |
+
ffmpeg.run(stream)
|
| 30 |
+
return output_path
|