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