File size: 5,362 Bytes
e54d50b
 
 
c1e50b1
 
 
 
e54d50b
 
 
c1e50b1
 
 
 
 
 
 
 
e54d50b
 
 
9cd7c6d
e54d50b
9cd7c6d
e54d50b
 
 
4c8b1a4
8db1169
c1e50b1
e54d50b
8db1169
4c8b1a4
e54d50b
80fb677
e54d50b
 
80fb677
ecf00ba
e54d50b
 
 
ecf00ba
 
e54d50b
 
6a5d6f8
e54d50b
 
ecf00ba
 
e54d50b
 
 
ecf00ba
 
 
e54d50b
 
ecf00ba
e54d50b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ecf00ba
e54d50b
 
 
 
4c8b1a4
ecf00ba
e54d50b
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
    )