Spaces:
Runtime error
Runtime error
Update app.py
#1
by
Marshalls
- opened
app.py
CHANGED
@@ -1,8 +1,64 @@
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from pathlib import Path
|
3 |
+
import tempfile
|
4 |
import gradio as gr
|
5 |
+
from moviepy.editor import VideoFileClip, AudioFileClip
|
6 |
+
allowed_medias = [".mp3", ".wav", ".ogg"]
|
7 |
+
def update(file,dclass):
|
8 |
+
if dclass == "":
|
9 |
+
raise gr.Error("请输入舞蹈类型.")
|
10 |
+
if dappear == "":
|
11 |
+
raise gr.Error("请输入人物外观.")
|
12 |
+
file_path = Path(file.name)
|
13 |
+
info = {}
|
14 |
+
info["size"] = os.path.getsize(file_path)
|
15 |
+
info["name"] = file_path.name
|
16 |
+
print(file_path.name)
|
17 |
+
file_extension = file_path.suffix
|
18 |
+
info["type"] = "audio"
|
19 |
+
audio = AudioFileClip(file.name)
|
20 |
+
info["duration"] = audio.duration
|
21 |
+
info["audio_channels"] = audio.nchannels
|
22 |
+
filename = file_path.name
|
23 |
+
######
|
24 |
+
audio.close()
|
25 |
+
#info为音频信息
|
26 |
+
videopath="myCoolSong.mp4"
|
27 |
+
#返回视频
|
28 |
+
if info["size"] > 100000000:
|
29 |
+
raise gr.Error(
|
30 |
+
"Please make sure all files are less than 100MB in size."
|
31 |
+
)
|
32 |
+
return videopath
|
33 |
|
34 |
+
with gr.Blocks() as demo:
|
35 |
+
gr.Markdown(
|
36 |
+
"""
|
37 |
+
# <span style="margin-right: 0.3rem;">🏞</span>音频自动生成舞蹈
|
38 |
+
上传音频,系统会自动生成对应的舞蹈
|
39 |
+
""",
|
40 |
+
elem_id="header",
|
41 |
+
)
|
42 |
+
with gr.Row():
|
43 |
+
with gr.Column():
|
44 |
+
user_file = gr.File(
|
45 |
+
file_count="single", label="音频文件", keep_filename=True,
|
46 |
+
file_types=allowed_medias
|
47 |
+
)
|
48 |
+
dclass=gr.Dropdown(["流行", "民族", "混合"], label="舞蹈类型", info="")
|
49 |
+
dappear=gr.Dropdown(["舞蹈服", "休闲服", "混合"], label="人物外观", info="")
|
50 |
+
number = gr.Slider(minimum=-0, maximum=20, value=1, step=1,
|
51 |
+
interactive=True, label="人物数量")
|
52 |
+
btn = gr.Button("Run", label="Run")
|
53 |
+
with gr.Column():
|
54 |
+
generated_video = gr.Video(
|
55 |
+
interactive=False, label="舞蹈视频", include_audio=True
|
56 |
+
)
|
57 |
+
# generated_command = gr.Markdown()
|
58 |
+
btn.click(
|
59 |
+
fn=update,
|
60 |
+
inputs=[user_file, dclass],
|
61 |
+
outputs=[generated_video]
|
62 |
+
)
|
63 |
+
if __name__ == "__main__":
|
64 |
+
demo.launch()
|