File size: 2,838 Bytes
9bb0e80
 
 
 
 
 
 
9c6c16a
9bb0e80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c6c16a
9bb0e80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c6c16a
 
9bb0e80
 
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
88
89
90
91
92
93
94
95
96
from __future__ import annotations

import os
import time
import sys
import PIL.Image
import numpy as np
import gradio as gr
import spaces
import cuid

from huggingface_hub import snapshot_download

# Set up paths
ProjectDir = os.path.dirname(os.path.abspath(__file__))
CheckpointsDir = os.path.join(ProjectDir, "checkpoints")
MuseVDir = os.path.join(ProjectDir, "MuseV")
GradioScriptsDir = os.path.join(MuseVDir, "scripts", "gradio")

# Add the MuseV paths to sys.path
paths_to_add = [
    GradioScriptsDir,
    MuseVDir,
    os.path.join(MuseVDir, "MMCM"),
    os.path.join(MuseVDir, "diffusers", "src"),
    os.path.join(MuseVDir, "controlnet_aux", "src"),
    os.path.dirname(os.path.abspath(__file__))
]

for path in paths_to_add:
    if os.path.exists(path) and path not in sys.path:
        sys.path.insert(0, path)
        print(f"Added {path} to PYTHONPATH")

def download_model():
    if not os.path.exists(CheckpointsDir):
        print("Checkpoint Not Downloaded, start downloading...")
        tic = time.time()
        snapshot_download(
            repo_id="TMElyralab/MuseV",
            local_dir=CheckpointsDir,
            max_workers=8,
        )
        toc = time.time()
        print(f"download cost {toc-tic} seconds")
    else:
        print("Already download the model.")

print("Starting model download...")
download_model()
print("Model download complete.")

print("Setting up paths...")
for path in sys.path:
    print(f"Path: {path}")

print("Attempting to import gradio modules...")
try:
    from gradio_video2video import online_v2v_inference
    print("Successfully imported video2video")
except Exception as e:
    print(f"Error importing video2video: {str(e)}")
    print(f"Current directory: {os.getcwd()}")
    print(f"Directory contents: {os.listdir('.')}")
    if os.path.exists(GradioScriptsDir):
        print(f"Gradio scripts directory contents: {os.listdir(GradioScriptsDir)}")

try:
    from gradio_text2video import online_t2v_inference
    print("Successfully imported text2video")
except Exception as e:
    print(f"Error importing text2video: {str(e)}")

ignore_video2video = False
max_image_edge = 1280

print("Setting up Gradio interface...")
demo = gr.Interface(
    fn=online_t2v_inference,
    inputs=[
        gr.Textbox(label="Prompt"),
        gr.Image(label="Reference Image"),
        gr.Number(label="Seed", value=-1),
        gr.Number(label="FPS", value=6),
        gr.Number(label="Width", value=-1),
        gr.Number(label="Height", value=-1),
        gr.Number(label="Video Length", value=12),
        gr.Number(label="Image Edge Ratio", value=1.0),
    ],
    outputs=gr.Video(),
    title="MuseV Demo",
    description="Generate videos from text and reference images"
)

print("Launching Gradio interface...")
demo.queue().launch(server_name="0.0.0.0", server_port=7860)