Spaces:
Running
Running
Quang Long
commited on
Commit
·
f96a1e4
1
Parent(s):
cdcee1d
update prepare_environment, fix symlinks
Browse files- README.md +3 -3
- prepare_environment.py +0 -11
- requirements_f5tts.txt +0 -2
- fix_symlinks.py → utils/fix_symlinks.py +0 -0
- utils/prepare_environment.py +79 -0
README.md
CHANGED
|
@@ -25,12 +25,12 @@ sudo apt-get update
|
|
| 25 |
sudo apt-get install sox ffmpeg
|
| 26 |
```
|
| 27 |
|
| 28 |
-
|
| 29 |
## Backup and Restore Volume
|
| 30 |
|
| 31 |
p/s: Need to mount backup folder to container
|
| 32 |
|
| 33 |
### Backup
|
|
|
|
| 34 |
```bash
|
| 35 |
tar -czvf /backup/data_cache_backup.tar.gz /home/user/.cache
|
| 36 |
tar -czvf /backup/data_gfpgan_backup.tar.gz /home/user/app/gfpgan
|
|
@@ -41,9 +41,9 @@ tar -czvf /backup/data_gfpgan_backup.tar.gz /home/user/app/gfpgan
|
|
| 41 |
```bash
|
| 42 |
mkdir -p /home/user/.cache
|
| 43 |
cd /home/user/.cache
|
| 44 |
-
tar xzvf /backup/data_cache_backup.tar.gz --strip 1
|
| 45 |
|
| 46 |
mkdir -p /home/user/app/gfpgan
|
| 47 |
cd /home/user/app/gfpgan
|
| 48 |
-
tar xzvf /backup/data_gfpgan_backup.tar.gz --strip 1
|
| 49 |
```
|
|
|
|
| 25 |
sudo apt-get install sox ffmpeg
|
| 26 |
```
|
| 27 |
|
|
|
|
| 28 |
## Backup and Restore Volume
|
| 29 |
|
| 30 |
p/s: Need to mount backup folder to container
|
| 31 |
|
| 32 |
### Backup
|
| 33 |
+
|
| 34 |
```bash
|
| 35 |
tar -czvf /backup/data_cache_backup.tar.gz /home/user/.cache
|
| 36 |
tar -czvf /backup/data_gfpgan_backup.tar.gz /home/user/app/gfpgan
|
|
|
|
| 41 |
```bash
|
| 42 |
mkdir -p /home/user/.cache
|
| 43 |
cd /home/user/.cache
|
| 44 |
+
tar -xzvf /backup/data_cache_backup.tar.gz --strip 1
|
| 45 |
|
| 46 |
mkdir -p /home/user/app/gfpgan
|
| 47 |
cd /home/user/app/gfpgan
|
| 48 |
+
tar -xzvf /backup/data_gfpgan_backup.tar.gz --strip 1
|
| 49 |
```
|
prepare_environment.py
DELETED
|
@@ -1,11 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
# help me write a python script to download a file from remote server and storage in /tmp
|
| 3 |
-
|
| 4 |
-
# if the file has already exist in /tmp, just skip download step
|
| 5 |
-
|
| 6 |
-
# the next step, create the volume, and extract the downloaded data into that volume
|
| 7 |
-
|
| 8 |
-
# the final step, cleanup /tmp
|
| 9 |
-
|
| 10 |
-
# http://172.16.15.118:9557/repository/atalink-hf-models/backups/data_cache_backup.tar.gz
|
| 11 |
-
# http://172.16.15.118:9557/repository/atalink-hf-models/backups/data_gfpgan_backup.tar.gz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements_f5tts.txt
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
f5_tts
|
| 2 |
-
pypinyin
|
|
|
|
|
|
|
|
|
fix_symlinks.py → utils/fix_symlinks.py
RENAMED
|
File without changes
|
utils/prepare_environment.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# help me write a python script to download a file from remote server and storage in /tmp
|
| 3 |
+
|
| 4 |
+
# if the file has already exist in /tmp, just skip download step
|
| 5 |
+
|
| 6 |
+
# the next step, create the volume, and extract the downloaded data into that volume
|
| 7 |
+
|
| 8 |
+
# the final step, cleanup /tmp
|
| 9 |
+
|
| 10 |
+
# http://172.16.15.118:9557/repository/atalink-hf-models/backups/data_cache_backup.tar.gz
|
| 11 |
+
# http://172.16.15.118:9557/repository/atalink-hf-models/backups/data_gfpgan_backup.tar.gz
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
#https://drive.usercontent.google.com/download?id=1Kuh-kZApPvI6EIBBy5fK1SRy8fGBHg4z&export=download&authuser=0&confirm=t&uuid=302429b1-d1d4-4aba-8320-ec04d80da509&at=AN8xHoqDn4UCrIap5o_SrGrqaD9F:1758299190305
|
| 15 |
+
import os
|
| 16 |
+
import requests
|
| 17 |
+
import shutil
|
| 18 |
+
import subprocess
|
| 19 |
+
import tarfile
|
| 20 |
+
|
| 21 |
+
DOWNLOADS = [
|
| 22 |
+
# "http://172.16.15.118:9557/repository/atalink-hf-models/backups/data_cache_backup.tar.gz",
|
| 23 |
+
# "http://172.16.15.118:9557/repository/atalink-hf-models/backups/data_gfpgan_backup.tar.gz"
|
| 24 |
+
"https://huggingface.co/hynt/F5-TTS-Vietnamese-ViVoice/resolve/main/config.json"
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
TMP_DIR = "/tmp"
|
| 29 |
+
VOLUME_PREFIX = "test_data_"
|
| 30 |
+
|
| 31 |
+
def download_file(url, dest_folder):
|
| 32 |
+
filename = os.path.basename(url)
|
| 33 |
+
dest_path = os.path.join(dest_folder, filename)
|
| 34 |
+
if os.path.exists(dest_path):
|
| 35 |
+
print(f"{filename} already exists at ```{dest_path}```, skipping download.")
|
| 36 |
+
return dest_path
|
| 37 |
+
print(f"Downloading {filename} ...")
|
| 38 |
+
with requests.get(url, stream=True) as r:
|
| 39 |
+
r.raise_for_status()
|
| 40 |
+
with open(dest_path, 'wb') as f:
|
| 41 |
+
shutil.copyfileobj(r.raw, f)
|
| 42 |
+
print(f"Downloaded {filename} at {dest_path}")
|
| 43 |
+
return dest_path
|
| 44 |
+
|
| 45 |
+
def create_volume_and_extract(tar_path, volume_name):
|
| 46 |
+
# Create Docker volume
|
| 47 |
+
subprocess.run(["docker", "volume", "create", volume_name], check=True)
|
| 48 |
+
# Extract tar.gz into the volume using a temporary container
|
| 49 |
+
print(f"Extracting {tar_path} into volume {volume_name} ...")
|
| 50 |
+
subprocess.run([
|
| 51 |
+
"docker", "run", "--rm", # Chạy container tạm thời, tự xóa sau khi xong
|
| 52 |
+
"-v", f"{volume_name}:/data", # Mount Docker volume (volume_name) vào thư mục /data trong container
|
| 53 |
+
"-v", f"{os.path.dirname(tar_path)}:/tmpdata", # Mount thư mục chứa file tar.gz trên host vào /tmpdata trong container
|
| 54 |
+
"busybox", # Image dùng để chạy container (ở đây là Ubuntu 22.04)
|
| 55 |
+
"bash", "-c", # Chạy lệnh bash trong container
|
| 56 |
+
f"tar -xzf /tmpdata/{os.path.basename(tar_path)} -C /data" # Lệnh giải nén file tar.gz từ /tmpdata vào /data
|
| 57 |
+
], check=True)
|
| 58 |
+
print(f"Extracted {tar_path} into volume {volume_name}")
|
| 59 |
+
|
| 60 |
+
def cleanup_tmp(files):
|
| 61 |
+
for f in files:
|
| 62 |
+
try:
|
| 63 |
+
os.remove(f)
|
| 64 |
+
print(f"Removed {f}")
|
| 65 |
+
except Exception as e:
|
| 66 |
+
print(f"Could not remove {f}: {e}")
|
| 67 |
+
|
| 68 |
+
def main():
|
| 69 |
+
downloaded_files = []
|
| 70 |
+
for url in DOWNLOADS:
|
| 71 |
+
tar_path = download_file(url, TMP_DIR)
|
| 72 |
+
downloaded_files.append(tar_path)
|
| 73 |
+
volume_name = VOLUME_PREFIX + os.path.splitext(os.path.splitext(os.path.basename(tar_path))[0])[0]
|
| 74 |
+
print("🚀 ~ volume_name:", volume_name)
|
| 75 |
+
# create_volume_and_extract(tar_path, volume_name)
|
| 76 |
+
# cleanup_tmp(downloaded_files)
|
| 77 |
+
|
| 78 |
+
if __name__ == "__main__":
|
| 79 |
+
main()
|