Spaces:
Runtime error
Runtime error
| 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) |