Spaces:
Sleeping
Sleeping
Create app.py
#1
by wuhaohan666 - opened
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def process_video(video_file):
|
| 4 |
+
"""
|
| 5 |
+
这里是您的视频处理逻辑。
|
| 6 |
+
您可以从Lecture 9的课件中找到代码,比如“自动去除视频静默片段”的案例。
|
| 7 |
+
此函数应返回处理后的视频文件路径。
|
| 8 |
+
"""
|
| 9 |
+
# 示例:这里只是一个占位,直接返回原文件,不做任何处理。
|
| 10 |
+
# 您需要替换为真实的处理代码,例如调用 moviepy, OpenCV 等库。
|
| 11 |
+
return video_file
|
| 12 |
+
|
| 13 |
+
with gr.Blocks() as demo:
|
| 14 |
+
gr.Markdown("# 🎥 我的视频处理应用")
|
| 15 |
+
|
| 16 |
+
with gr.Row():
|
| 17 |
+
with gr.Column():
|
| 18 |
+
# 核心:创建一个允许上传视频的输入组件
|
| 19 |
+
input_video = gr.Video(
|
| 20 |
+
label="请上传您的视频文件",
|
| 21 |
+
sources=["upload"], # 指定来源为“上传”
|
| 22 |
+
format="mp4", # 可选,指定期望的格式
|
| 23 |
+
interactive=True
|
| 24 |
+
)
|
| 25 |
+
process_btn = gr.Button("开始处理", variant="primary")
|
| 26 |
+
|
| 27 |
+
with gr.Column():
|
| 28 |
+
# 用于显示处理后视频的输出组件
|
| 29 |
+
output_video = gr.Video(label="处理结果")
|
| 30 |
+
|
| 31 |
+
# 将按钮点击事件与处理函数绑定
|
| 32 |
+
process_btn.click(fn=process_video, inpu
|