Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,50 +7,14 @@ import spaces
|
|
| 7 |
import torch
|
| 8 |
import os
|
| 9 |
import sys
|
| 10 |
-
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'xcodec_mini_infer'))
|
| 11 |
-
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'xcodec_mini_infer', 'descriptaudiocodec'))
|
| 12 |
-
import argparse
|
| 13 |
-
import numpy as np
|
| 14 |
-
import json
|
| 15 |
-
from omegaconf import OmegaConf
|
| 16 |
-
import torchaudio
|
| 17 |
-
from torchaudio.transforms import Resample
|
| 18 |
-
import soundfile as sf
|
| 19 |
-
|
| 20 |
-
import uuid
|
| 21 |
-
from tqdm import tqdm
|
| 22 |
-
from einops import rearrange
|
| 23 |
-
from codecmanipulator import CodecManipulator
|
| 24 |
-
from mmtokenizer import _MMSentencePieceTokenizer
|
| 25 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM, LogitsProcessor, LogitsProcessorList
|
| 26 |
-
import glob
|
| 27 |
-
import time
|
| 28 |
-
import copy
|
| 29 |
-
from collections import Counter
|
| 30 |
-
from models.soundstream_hubert_new import SoundStream
|
| 31 |
-
from vocoder import build_codec_model, process_audio
|
| 32 |
-
from post_process_audio import replace_low_freq_with_energy_matched
|
| 33 |
-
import re
|
| 34 |
-
|
| 35 |
-
is_shared_ui = True if "innova-ai/YuE-music-generator-demo" in os.environ['SPACE_ID'] else False
|
| 36 |
-
|
| 37 |
-
# Install required package
|
| 38 |
-
def install_flash_attn():
|
| 39 |
-
try:
|
| 40 |
-
print("Installing flash-attn...")
|
| 41 |
-
# Install flash attention
|
| 42 |
-
subprocess.run(
|
| 43 |
-
"pip install flash-attn --no-build-isolation",
|
| 44 |
-
env={"FLASH_ATTENTION_SKIP_CUDA_BUILD": "TRUE"},
|
| 45 |
-
shell=True,
|
| 46 |
-
)
|
| 47 |
-
print("flash-attn installed successfully!")
|
| 48 |
-
except subprocess.CalledProcessError as e:
|
| 49 |
-
print(f"Failed to install flash-attn: {e}")
|
| 50 |
-
exit(1)
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
from huggingface_hub import snapshot_download
|
| 56 |
|
|
@@ -78,6 +42,33 @@ except FileNotFoundError:
|
|
| 78 |
print(f"Directory not found: {inference_dir}")
|
| 79 |
exit(1)
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
def empty_output_folder(output_dir):
|
| 82 |
# List all files in the output directory
|
| 83 |
files = os.listdir(output_dir)
|
|
|
|
| 7 |
import torch
|
| 8 |
import os
|
| 9 |
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
print("Installing flash-attn...")
|
| 12 |
+
# Install flash attention
|
| 13 |
+
subprocess.run(
|
| 14 |
+
"pip install flash-attn --no-build-isolation",
|
| 15 |
+
env={"FLASH_ATTENTION_SKIP_CUDA_BUILD": "TRUE"},
|
| 16 |
+
shell=True,
|
| 17 |
+
)
|
| 18 |
|
| 19 |
from huggingface_hub import snapshot_download
|
| 20 |
|
|
|
|
| 42 |
print(f"Directory not found: {inference_dir}")
|
| 43 |
exit(1)
|
| 44 |
|
| 45 |
+
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'xcodec_mini_infer'))
|
| 46 |
+
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'xcodec_mini_infer', 'descriptaudiocodec'))
|
| 47 |
+
import argparse
|
| 48 |
+
import numpy as np
|
| 49 |
+
import json
|
| 50 |
+
from omegaconf import OmegaConf
|
| 51 |
+
import torchaudio
|
| 52 |
+
from torchaudio.transforms import Resample
|
| 53 |
+
import soundfile as sf
|
| 54 |
+
|
| 55 |
+
import uuid
|
| 56 |
+
from tqdm import tqdm
|
| 57 |
+
from einops import rearrange
|
| 58 |
+
from codecmanipulator import CodecManipulator
|
| 59 |
+
from mmtokenizer import _MMSentencePieceTokenizer
|
| 60 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, LogitsProcessor, LogitsProcessorList
|
| 61 |
+
import glob
|
| 62 |
+
import time
|
| 63 |
+
import copy
|
| 64 |
+
from collections import Counter
|
| 65 |
+
from models.soundstream_hubert_new import SoundStream
|
| 66 |
+
from vocoder import build_codec_model, process_audio
|
| 67 |
+
from post_process_audio import replace_low_freq_with_energy_matched
|
| 68 |
+
import re
|
| 69 |
+
|
| 70 |
+
is_shared_ui = True if "innova-ai/YuE-music-generator-demo" in os.environ['SPACE_ID'] else False
|
| 71 |
+
|
| 72 |
def empty_output_folder(output_dir):
|
| 73 |
# List all files in the output directory
|
| 74 |
files = os.listdir(output_dir)
|