Spaces:
Paused
Paused
Phil Sobrepena commited on
Commit ·
d07a8ac
1
Parent(s): 2fd3693
updates to app and reqs
Browse filesFiles changed (3)
- DockerfileDeleted-58
- app.py+75-76
- requirements.txt+27-25
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758FROM nvidia/cuda:11.8.0-runtime-ubuntu22.04
# # Clone MMAudio# RUN git clone https://huggingface.co/autophil/MMAudio_SS
WORKDIR /code/MMAudio_SS
# Install system dependenciesRUN apt-get update && apt-get install -y \ python3.10 \ python3.10-distutils \ python3-pip \ git \ ffmpeg \ libsm6 \ libxext6 \ curl \ libsndfile1 \ && rm -rf /var/lib/apt/lists/*
# # Ensure we're using Python 3.10# RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
# # Install pip for Python 3.10 and upgrade it# RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10 && \# pip3 install --no-cache-dir --upgrade pip setuptools wheel
# Install RequirementsRUN pip3 install --no-cache-dir -r requirements.txt
# Install PyTorch and related packages first (as recommended in README)RUN pip3 install --no-cache-dir \ torch \ torchvision \ torchaudio \ --index-url https://download.pytorch.org/whl/cu118 --upgrade # Install MMAudio last (as recommended in README)RUN pip3 --no-cache-dir install -e .
# Create output directoryRUN mkdir -p output/gradio && chmod 777 output/gradio
# # Copy app.py (we'll use our own version instead of the one from the repo)# COPY app.py .
# Set environment variables for Hugging Face SpacesENV PYTHONUNBUFFERED=1ENV GRADIO_SERVER_NAME=0.0.0.0ENV GRADIO_SERVER_PORT=7860ENV PYTHONPATH=/code/MMAudio
# Expose Gradio portEXPOSE 7860
# Run the appCMD ["python3", "app.py"]123456789101112137 unmodified lines2122232425262728293031323323 unmodified lines5758596061626324 unmodified lines88899091929394959697989910010124 unmodified lines12612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017116 unmodified lines18818919019119219319419519619719819920020120220320420520620720820917 unmodified lines227228229230231232233234235236237238239import gcimport loggingfrom argparse import ArgumentParserfrom datetime import datetimefrom fractions import Fractionfrom pathlib import Pathimport gradio as grimport torchimport torchaudiofrom mmaudio.eval_utils import (ModelConfig, VideoInfo, all_model_cfg, generate, load_image,load_video, make_video, setup_eval_logging)7 unmodified lineslog = logging.getLogger()device = 'cpu'if torch.cuda.is_available():device = 'cuda'elif torch.backends.mps.is_available():device = 'mps'else:log.warning('CUDA/MPS are not available, running on CPU')dtype = torch.bfloat16model: ModelConfig = all_model_cfg['large_44k_v2']23 unmodified linesnet, feature_utils, seq_cfg = get_model()@torch.inference_mode()def video_to_audio(video: gr.Video, prompt: str, negative_prompt: str, seed: int, num_steps: int,cfg_strength: float, duration: float):24 unmodified linescfg_strength=cfg_strength)audio = audios.float().cpu()[0]current_time_string = datetime.now().strftime('%Y%m%d_%H%M%S')output_dir.mkdir(exist_ok=True, parents=True)video_save_path = output_dir / f'{current_time_string}.mp4'make_video(video_info, video_save_path, audio, sampling_rate=seq_cfg.sampling_rate)gc.collect()return video_save_path@torch.inference_mode()def image_to_audio(image: gr.Image, prompt: str, negative_prompt: str, seed: int, num_steps: int,cfg_strength: float, duration: float):24 unmodified linesimage_input=True)audio = audios.float().cpu()[0]current_time_string = datetime.now().strftime('%Y%m%d_%H%M%S')output_dir.mkdir(exist_ok=True, parents=True)video_save_path = output_dir / f'{current_time_string}.mp4'video_info = VideoInfo.from_image_info(image_info, duration, fps=Fraction(1))make_video(video_info, video_save_path, audio, sampling_rate=seq_cfg.sampling_rate)gc.collect()return video_save_path@torch.inference_mode()def text_to_audio(prompt: str, negative_prompt: str, seed: int, num_steps: int, cfg_strength: float,duration: float):rng = torch.Generator(device=device)if seed >= 0:rng.manual_seed(seed)else:rng.seed()fm = FlowMatching(min_sigma=0, inference_mode='euler', num_steps=num_steps)clip_frames = sync_frames = Noneseq_cfg.duration = durationnet.update_seq_lengths(seq_cfg.latent_seq_len, seq_cfg.clip_seq_len, seq_cfg.sync_seq_len)audios = generate(clip_frames,sync_frames, [prompt],negative_text=[negative_prompt],feature_utils=feature_utils,net=net,fm=fm,rng=rng,cfg_strength=cfg_strength)audio = audios.float().cpu()[0]current_time_string = datetime.now().strftime('%Y%m%d_%H%M%S')output_dir.mkdir(exist_ok=True, parents=True)audio_save_path = output_dir / f'{current_time_string}.flac'torchaudio.save(audio_save_path, audio, seq_cfg.sampling_rate)gc.collect()return audio_save_pathvideo_to_audio_tab = gr.Interface(16 unmodified linestitle='Sonisphere - Sonic Branding Tool',)text_to_audio_tab = gr.Interface(fn=text_to_audio,description=""" Text-to-Audio""",inputs=[gr.Text(label='Prompt'),gr.Text(label='Negative prompt'),gr.Number(label='Seed (-1: random)', value=-1, precision=0, minimum=-1),gr.Number(label='Num steps', value=25, precision=0, minimum=1),gr.Number(label='Guidance Strength', value=4.5, minimum=1),gr.Number(label='Duration (sec)', value=8, minimum=1),],outputs='audio',cache_examples=False,title='Sonisphere - Sonic Branding Tool',)image_to_audio_tab = gr.Interface(fn=image_to_audio,17 unmodified lines)if __name__ == "__main__":parser = ArgumentParser()parser.add_argument('--port', type=int, default=7860)args = parser.parse_args()gr.TabbedInterface([video_to_audio_tab, text_to_audio_tab, image_to_audio_tab],['Video-to-Audio', 'Text-to-Audio', 'Image-to-Audio (experimental)']).launch(server_name="0.0.0.0",server_port=7860,auth=("admin", "sonisphere"),allowed_paths=[output_dir])1234567891011121314151617187 unmodified lines2627282930313223 unmodified lines5657585960616224 unmodified lines8788899091929394959697989910010124 unmodified lines12612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117216 unmodified lines18919019119219319419519619719819920020120220320420520620720820921017 unmodified lines228229230231232233234235236237238import spacesimport loggingfrom datetime import datetimefrom pathlib import Pathimport gradio as grimport torchimport torchaudioimport ostry:import mmaudioexcept ImportError:os.system("pip install -e .")import mmaudiofrom mmaudio.eval_utils import (ModelConfig, VideoInfo, all_model_cfg, generate, load_image,load_video, make_video, setup_eval_logging)7 unmodified lineslog = logging.getLogger()device = 'cuda'dtype = torch.bfloat16model: ModelConfig = all_model_cfg['large_44k_v2']23 unmodified linesnet, feature_utils, seq_cfg = get_model()@spaces.GPU(duration=120)@torch.inference_mode()def video_to_audio(video: gr.Video, prompt: str, negative_prompt: str, seed: int, num_steps: int,cfg_strength: float, duration: float):24 unmodified linescfg_strength=cfg_strength)audio = audios.float().cpu()[0]# current_time_string = datetime.now().strftime('%Y%m%d_%H%M%S')# output_dir.mkdir(exist_ok=True, parents=True)# video_save_path = output_dir / f'{current_time_string}.mp4'video_save_path = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4').namemake_video(video_info, video_save_path, audio, sampling_rate=seq_cfg.sampling_rate)log.info(f'Saved video to {video_save_path}')return video_save_path@spaces.GPU(duration=120)@torch.inference_mode()def image_to_audio(image: gr.Image, prompt: str, negative_prompt: str, seed: int, num_steps: int,cfg_strength: float, duration: float):24 unmodified linesimage_input=True)audio = audios.float().cpu()[0]# current_time_string = datetime.now().strftime('%Y%m%d_%H%M%S')# output_dir.mkdir(exist_ok=True, parents=True)# video_save_path = output_dir / f'{current_time_string}.mp4'video_info = VideoInfo.from_image_info(image_info, duration, fps=Fraction(1))video_save_path = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4').namemake_video(video_info, video_save_path, audio, sampling_rate=seq_cfg.sampling_rate)log.info(f'Saved video to {video_save_path}')return video_save_path# @spaces.GPU(duration=120)# @torch.inference_mode()# def text_to_audio(prompt: str, negative_prompt: str, seed: int, num_steps: int, cfg_strength: float,# duration: float):# rng = torch.Generator(device=device)# if seed >= 0:# rng.manual_seed(seed)# else:# rng.seed()# fm = FlowMatching(min_sigma=0, inference_mode='euler', num_steps=num_steps)# clip_frames = sync_frames = None# seq_cfg.duration = duration# net.update_seq_lengths(seq_cfg.latent_seq_len, seq_cfg.clip_seq_len, seq_cfg.sync_seq_len)# audios = generate(clip_frames,# sync_frames, [prompt],# negative_text=[negative_prompt],# feature_utils=feature_utils,# net=net,# fm=fm,# rng=rng,# cfg_strength=cfg_strength)# audio = audios.float().cpu()[0]# current_time_string = datetime.now().strftime('%Y%m%d_%H%M%S')# output_dir.mkdir(exist_ok=True, parents=True)# audio_save_path = output_dir / f'{current_time_string}.flac'# torchaudio.save(audio_save_path, audio, seq_cfg.sampling_rate)# gc.collect()# return audio_save_pathvideo_to_audio_tab = gr.Interface(16 unmodified linestitle='Sonisphere - Sonic Branding Tool',)# text_to_audio_tab = gr.Interface(# fn=text_to_audio,# description=""" Text-to-Audio# """,# inputs=[# gr.Text(label='Prompt'),# gr.Text(label='Negative prompt'),# gr.Number(label='Seed (-1: random)', value=-1, precision=0, minimum=-1),# gr.Number(label='Num steps', value=25, precision=0, minimum=1),# gr.Number(label='Guidance Strength', value=4.5, minimum=1),# gr.Number(label='Duration (sec)', value=8, minimum=1),# ],# outputs='audio',# cache_examples=False,# title='Sonisphere - Sonic Branding Tool',# )image_to_audio_tab = gr.Interface(fn=image_to_audio,17 unmodified lines)if __name__ == "__main__":# parser = ArgumentParser()# parser.add_argument('--port', type=int, default=7860)# args = parser.parse_args()gr.TabbedInterface([video_to_audio_tab, image_to_audio_tab],['Video-to-Audio', 'Image-to-Audio']).launch(auth=("admin", "sonisphere"),allowed_paths=[output_dir])
12345678910111213141516171819202122232425numpy==1.24.3torch==2.6.0torchvision==0.21.0torchaudio==2.6.0torchdiffeq==0.2.3omegaconf>=2.3.0huggingface_hub>=0.26.1Pillow>=9.5opencv-python-headless>=4.8gradio>=4.19.2einops>=0.6open_clip_torch>=2.29.0av>=14.0.1transformers>=4.36.2ffmpeg-python>=0.2.0moviepy>=1.0.3python-multipart>=0.0.9colorlog==6.8.2pandas>=2.0.0tensordict>=0.2.0hydra-core>=1.3.2tqdm>=4.65.0librosa>=0.10.1timm>=0.9.12requests>=2.31.0123456789101112131415161718192021222324252627torch == 2.4.0torchvisiontorchaudiopython-dotenvcythongitpython >= 3.1tensorboard >= 2.11numpy >= 1.21, <2.1Pillow >= 9.5opencv-python >= 4.8scipy >= 1.7tqdm >= 4.66.1gradio >= 3.34einops >= 0.6hydra-core >= 1.3.2requeststorchdiffeqlibrosa >= 0.8.1nitrous-emasafetensorsauralosshydra_colorlogtensordictcolorlogopen_clip_torchsoundfileav
DockerfileDeleted-58
app.py+75-76
requirements.txt+27-25