schnik's picture
Upload folder using huggingface_hub
8db1169 verified
raw
history blame contribute delete
No virus
5.36 kB
import gradio as gr
import os
global current_video_index
current_video_index = "v"
def load_cached_video(video_file, dataset, lora, size):
output = "./cached_examples/"
output += "peft" if lora else "audiocraft"
output += "_" + dataset + "_" + size + "_" + video_file[-7:-4]
output += "_" + globals()["current_video_index"] + ".mp4"
# roll trough the video indexes
if globals()["current_video_index"] == "v":
globals()["current_video_index"] = "v1"
elif globals()["current_video_index"] == "v1":
globals()["current_video_index"] = "v2"
else:
globals()["current_video_index"] = "v"
if not os.path.exists(output):
print(output)
raise gr.Error("This combination of video and model has not been cached. Try one of the listed examples instead.")
gr.Warning("This interface is running on CPU. Only cached generated examples are displayed here, no new music is generated. Please be patient, as the videos might take a while to download.")
print("Displaying video: " + output)
return output
with gr.Blocks() as demo:
gr.Markdown('**WARNING**: <span style="color:orange">Multiple video examples have to be downloaded to use this UI properly. If no video is loading after a couple of seconds, please click on one of the examples below.</span>')
gr.Interface(fn=load_cached_video,
inputs=[
gr.Video(value="./videos/n_3.mp4",
label="Original Video",
min_length=5,
interactive=False,
max_length=20,
show_download_button=True,
include_audio=True
),
gr.Radio(["nature", "symmv"],
value="nature",
label="Available Models",
info="Choose one of the datasets on which the models has been trained on. Nature is a dataset of calm and relaxing sounds, symmv contains charts music. The model will generate audio that is similar to the training data."
),
gr.Radio([False, True],
label="Use the LoRA version of the MusicGen Audio Decoder",
value=True,
info="If set to 'True' the MusicGen Audio Decoder models trained with LoRA "
"(Low Rank Adaptation) are used. If set to 'False', the original "
"MusicGen models are used instead."
),
gr.Radio(["small", "medium", "large"],
label="Model Size",
value="large",
info="Choose one of the available model sizes. This effects the enocder and the deocder model. The larger models are more likely produce "
"results of higher audio quality, but also take more time to generate it."
),
],
outputs=[gr.Video(label="Generated Result")],
examples=[
[os.path.abspath("./videos/n_1.mp4"), "nature", False, "large"],
[os.path.abspath("./videos/n_2.mp4"), "nature", False, "large"],
[os.path.abspath("./videos/n_3.mp4"), "nature", False, "large"],
[os.path.abspath("./videos/n_4.mp4"), "nature", False, "large"],
[os.path.abspath("./videos/n_5.mp4"), "nature", True, "large"],
[os.path.abspath("./videos/n_6.mp4"), "nature", True, "large"],
[os.path.abspath("./videos/n_7.mp4"), "nature", True, "large"],
[os.path.abspath("./videos/n_8.mp4"), "nature", True, "large"],
[os.path.abspath("./videos/s_1.mp4"), "symmv", False, "large"],
[os.path.abspath("./videos/s_2.mp4"), "symmv", False, "large"],
[os.path.abspath("./videos/s_3.mp4"), "symmv", False, "large"],
[os.path.abspath("./videos/s_4.mp4"), "symmv", False, "large"],
[os.path.abspath("./videos/s_5.mp4"), "symmv", True, "large"],
[os.path.abspath("./videos/s_6.mp4"), "symmv", True, "large"],
[os.path.abspath("./videos/s_7.mp4"), "symmv", True, "large"],
[os.path.abspath("./videos/s_8.mp4"), "symmv", True, "large"],
],
examples_per_page=20,
cache_examples=False,
)
if __name__ == "__main__":
demo.launch(
share=False
)