Long Trinh-Quang commited on
Commit
e578b02
·
1 Parent(s): f96a1e4

[DEV] update ui app.py, update prepare_env.py

Browse files
Files changed (2) hide show
  1. app.py +34 -18
  2. utils/prepare_environment.py +47 -26
app.py CHANGED
@@ -114,35 +114,22 @@ def sadtalker_demo():
114
  f"""
115
  ![logo](https://vietnam.atalink.com/favicon.ico)
116
 
117
- ## F5-TTS & SadTalker
118
 
119
- Nhập text, upload sample voice và ảnh để tạo video nói chuyện. Chủ đạo Atalink Blue.
120
  """
121
  )
122
- with gr.Tab("Lịch sử video"):
123
- with gr.Row(elem_classes="gr-row"):
124
- video_list = gr.Dropdown(
125
- choices=list_videos(),
126
- label="Chọn video để xem",
127
- interactive=True,
128
- scale=1,
129
- )
130
- video_player = gr.Video(
131
- height=180, width=180, label="Video lịch sử", scale=1
132
- )
133
- video_list.change(lambda x: x, inputs=video_list, outputs=video_player)
134
-
135
  with gr.Tab("Tạo video mới"):
136
  with gr.Row(elem_classes="gr-row"):
137
  ref_audio = gr.Audio(label="🔊 Sample Voice", type="filepath")
138
  ref_text = gr.Textbox(
139
- label="📝 Reference Transcript (optional)",
140
  placeholder="Nhập transcript tiếng Việt cho sample voice nếu có...",
141
  lines=2,
142
  )
143
  with gr.Row(elem_classes="gr-row"):
144
  gen_text = gr.Textbox(
145
- label="📝 Text",
146
  placeholder="Nhập nội dung để tạo giọng nói...",
147
  lines=3,
148
  )
@@ -214,12 +201,28 @@ def sadtalker_demo():
214
  use_idle_mode = gr.Checkbox(label="Idle Animation")
215
  length_of_audio = gr.Number(value=5, label="Độ dài video (giây)")
216
  blink_every = gr.Checkbox(label="Chớp mắt", value=True)
217
- btn_generate = gr.Button("🔥 Tạo giọng nói & video", elem_id="btn-generate")
 
 
218
  with gr.Row(elem_classes="gr-row"):
219
  output_audio = gr.Audio(label="🎧 Audio đã tạo", type="filepath")
220
  gen_video = gr.Video(
221
  label="Video đã tạo", format="mp4", scale=1, height=180, width=180
222
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
  btn_generate.click(
224
  generate_voice_and_video,
225
  inputs=[
@@ -245,6 +248,19 @@ def sadtalker_demo():
245
  ],
246
  outputs=[output_audio, gen_video],
247
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  return sadtalker_interface
249
 
250
 
 
114
  f"""
115
  ![logo](https://vietnam.atalink.com/favicon.ico)
116
 
117
+ ## Atalink TTS_Talker
118
 
119
+ Nhập text, upload sample voice và ảnh để tạo video nói chuyện.
120
  """
121
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  with gr.Tab("Tạo video mới"):
123
  with gr.Row(elem_classes="gr-row"):
124
  ref_audio = gr.Audio(label="🔊 Sample Voice", type="filepath")
125
  ref_text = gr.Textbox(
126
+ label="📝 Nội dung tham khảo (tùy chọn)",
127
  placeholder="Nhập transcript tiếng Việt cho sample voice nếu có...",
128
  lines=2,
129
  )
130
  with gr.Row(elem_classes="gr-row"):
131
  gen_text = gr.Textbox(
132
+ label="📝 Nội dung cần tạo",
133
  placeholder="Nhập nội dung để tạo giọng nói...",
134
  lines=3,
135
  )
 
201
  use_idle_mode = gr.Checkbox(label="Idle Animation")
202
  length_of_audio = gr.Number(value=5, label="Độ dài video (giây)")
203
  blink_every = gr.Checkbox(label="Chớp mắt", value=True)
204
+ btn_generate = gr.Button(
205
+ "🔥 Tạo giọng nói & video", elem_id="btn-generate", interactive=False
206
+ )
207
  with gr.Row(elem_classes="gr-row"):
208
  output_audio = gr.Audio(label="🎧 Audio đã tạo", type="filepath")
209
  gen_video = gr.Video(
210
  label="Video đã tạo", format="mp4", scale=1, height=180, width=180
211
  )
212
+
213
+ def enable_generate(audio, text, image):
214
+ return gr.update(interactive=bool(audio and text and image))
215
+
216
+ ref_audio.change(
217
+ enable_generate, [ref_audio, gen_text, source_image], btn_generate
218
+ )
219
+ gen_text.change(
220
+ enable_generate, [ref_audio, gen_text, source_image], btn_generate
221
+ )
222
+ source_image.change(
223
+ enable_generate, [ref_audio, gen_text, source_image], btn_generate
224
+ )
225
+
226
  btn_generate.click(
227
  generate_voice_and_video,
228
  inputs=[
 
248
  ],
249
  outputs=[output_audio, gen_video],
250
  )
251
+ with gr.Tab("Lịch sử video"):
252
+ with gr.Row(elem_classes="gr-row"):
253
+ video_list = gr.Dropdown(
254
+ choices=list_videos(),
255
+ label="Chọn video để xem",
256
+ interactive=True,
257
+ scale=1,
258
+ )
259
+ video_player = gr.Video(
260
+ height=180, width=180, label="Video lịch sử", scale=1
261
+ )
262
+ video_list.change(lambda x: x, inputs=video_list, outputs=video_player)
263
+
264
  return sadtalker_interface
265
 
266
 
utils/prepare_environment.py CHANGED
@@ -1,4 +1,3 @@
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
@@ -10,70 +9,92 @@
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 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()
 
 
1
  # help me write a python script to download a file from remote server and storage in /tmp
2
 
3
  # if the file has already exist in /tmp, just skip download step
 
9
  # http://172.16.15.118:9557/repository/atalink-hf-models/backups/data_cache_backup.tar.gz
10
  # http://172.16.15.118:9557/repository/atalink-hf-models/backups/data_gfpgan_backup.tar.gz
11
 
 
 
12
  import os
13
  import requests
14
  import shutil
15
  import subprocess
16
  import tarfile
17
+ from tqdm import tqdm
18
 
19
  DOWNLOADS = [
20
+ "http://172.16.15.118:9557/repository/atalink-hf-models/backups/data_cache_backup.tar.gz",
21
+ "http://172.16.15.118:9557/repository/atalink-hf-models/backups/data_gfpgan_backup.tar.gz"
22
+ # "https://huggingface.co/hynt/F5-TTS-Vietnamese-ViVoice/resolve/main/config.json"
23
  ]
24
 
25
 
26
  TMP_DIR = "/tmp"
27
+ VOLUME_PREFIX = "test_"
28
+
29
 
30
  def download_file(url, dest_folder):
31
  filename = os.path.basename(url)
32
  dest_path = os.path.join(dest_folder, filename)
33
  if os.path.exists(dest_path):
34
+ print(f"✅ [SKIP] {filename} already exists at \033[96m{dest_path}\033[0m, skipping download.")
35
  return dest_path
36
+ print(f"\n📥 [START] Downloading: \033[1;36m{filename}\033[0m → \033[96m{dest_path}\033[0m")
37
  with requests.get(url, stream=True) as r:
38
  r.raise_for_status()
39
+ total = int(r.headers.get("content-length", 0))
40
+ chunk_size = 1024 * 1024 # 1MB
41
+ with open(dest_path, "wb") as f, tqdm(
42
+ total=total, unit="B", unit_scale=True, desc=filename
43
+ ) as pbar:
44
+ for chunk in r.iter_content(chunk_size=chunk_size):
45
+ if chunk:
46
+ f.write(chunk)
47
+ pbar.update(len(chunk))
48
+ print(f"✅ [DONE] Downloaded: \033[1;32m{filename}\033[0m → \033[96m{dest_path}\033[0m\n")
49
  return dest_path
50
 
51
+
52
  def create_volume_and_extract(tar_path, volume_name):
53
  # Create Docker volume
54
  subprocess.run(["docker", "volume", "create", volume_name], check=True)
55
  # Extract tar.gz into the volume using a temporary container
56
+ print(f"\n📦 [EXTRACT] Extracting \033[1;36m{os.path.basename(tar_path)}\033[0m into Docker volume \033[1;33m{volume_name}\033[0m ...")
57
+ subprocess.run(
58
+ [
59
+ "docker",
60
+ "run",
61
+ "--rm", # Chạy container tạm thời, tự xóa sau khi xong
62
+ "-v",
63
+ f"{volume_name}:/data", # Mount Docker volume (volume_name) vào thư mục /data trong container
64
+ "-v",
65
+ f"{os.path.dirname(tar_path)}:/tmpdata", # Mount thư mục chứa file tar.gz trên host vào /tmpdata trong container
66
+ "busybox", # Image dùng để chạy container (ở đây là Ubuntu 22.04)
67
+ "bash",
68
+ "-c", # Chạy lệnh bash trong container
69
+ 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
70
+ ],
71
+ check=True,
72
+ )
73
+ print(f"✅ [DONE] Extracted \033[1;36m{os.path.basename(tar_path)}\033[0m into volume \033[1;33m{volume_name}\033[0m\n")
74
+
75
 
76
  def cleanup_tmp(files):
77
  for f in files:
78
  try:
79
  os.remove(f)
80
+ print(f"🧹 [CLEANUP] Removed \033[96m{f}\033[0m")
81
  except Exception as e:
82
+ print(f"⚠️ [CLEANUP] Could not remove \033[96m{f}\033[0m: {e}")
83
+
84
 
85
  def main():
86
  downloaded_files = []
87
  for url in DOWNLOADS:
88
  tar_path = download_file(url, TMP_DIR)
89
  downloaded_files.append(tar_path)
90
+ volume_name = (
91
+ VOLUME_PREFIX
92
+ + os.path.splitext(os.path.splitext(os.path.basename(tar_path))[0])[0]
93
+ )
94
+ print(f"🚀 [VOLUME] Name: \033[1;33m{volume_name}\033[0m")
95
  # create_volume_and_extract(tar_path, volume_name)
96
  # cleanup_tmp(downloaded_files)
97
 
98
+
99
  if __name__ == "__main__":
100
  main()