Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,24 @@
|
|
| 1 |
import subprocess
|
| 2 |
import os
|
| 3 |
import sys
|
|
|
|
| 4 |
from pathlib import Path
|
| 5 |
import argparse
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
-
# โ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
if not os.path.exists("./models/fantasytalking_model.ckpt"):
|
| 10 |
print("๐ ๏ธ ุฌุงุฑู ุชุญู
ูู ุงููู
ุงุฐุฌ ุนุจุฑ download_models.py ...")
|
| 11 |
subprocess.run(["python", "download_models.py"])
|
|
@@ -19,22 +32,22 @@ from LLM.llm import generate_reply
|
|
| 19 |
from TTS_X.tts import generate_voice
|
| 20 |
from FantasyTalking.infer import load_models, main
|
| 21 |
|
| 22 |
-
# โ
|
| 23 |
args_template = argparse.Namespace(
|
| 24 |
fantasytalking_model_path="./models/fantasytalking_model.ckpt",
|
| 25 |
wav2vec_model_dir="./models/wav2vec2-base-960h",
|
| 26 |
-
wan_model_dir="./models/Wan2.1-I2V-14B-720P",
|
| 27 |
image_path="",
|
| 28 |
audio_path="",
|
| 29 |
prompt="",
|
| 30 |
output_dir="./output",
|
| 31 |
-
image_size=
|
| 32 |
audio_scale=1.0,
|
| 33 |
-
prompt_cfg_scale=
|
| 34 |
-
audio_cfg_scale=
|
| 35 |
-
max_num_frames=
|
| 36 |
-
inference_steps=
|
| 37 |
-
fps=
|
| 38 |
num_persistent_param_in_dit=None,
|
| 39 |
seed=1111
|
| 40 |
)
|
|
@@ -44,14 +57,8 @@ print("๐ ุฌุงุฑู ุชุญู
ูู FantasyTalking ู Wav2Vec...")
|
|
| 44 |
pipe, fantasytalking, wav2vec_processor, wav2vec = load_models(args_template)
|
| 45 |
print("โ
ุชู
ุงูุชุญู
ูู!")
|
| 46 |
|
| 47 |
-
# โ
ุชูููุฏ
|
| 48 |
def generate_video(image_path, audio_path, prompt, output_dir="./output"):
|
| 49 |
-
print(f"[๐จ] generate_video() ุจุฏุฃ ุงูุชุดุบูู")
|
| 50 |
-
print(f"[๐] image_path: {image_path}")
|
| 51 |
-
print(f"[๐] audio_path: {audio_path}")
|
| 52 |
-
print(f"[๐ฌ] prompt: {prompt}")
|
| 53 |
-
print(f"[๐] output_dir: {output_dir}")
|
| 54 |
-
|
| 55 |
args = argparse.Namespace(
|
| 56 |
**vars(args_template),
|
| 57 |
image_path=image_path,
|
|
@@ -59,28 +66,18 @@ def generate_video(image_path, audio_path, prompt, output_dir="./output"):
|
|
| 59 |
prompt=prompt,
|
| 60 |
output_dir=output_dir
|
| 61 |
)
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
print(f"[โ
] generate_video() ุงูุชููุ ุงูููุฏูู ู
ุญููุธ ููุง: {video_path}")
|
| 65 |
-
return video_path
|
| 66 |
-
|
| 67 |
-
# โ
ุฎุท ุงูุฃูุงุจูุจ ุงููุงู
ู - ู
ุน ุทุจุงุนุฉ Debug
|
| 68 |
def full_pipeline(user_audio, user_image):
|
| 69 |
-
print("[๐] full_pipeline() ุจุฏุฃ ุงูุชุดุบูู")
|
| 70 |
-
print(f"[๐] ู
ูู ุงูุตูุช ุงูู
ูุฏุฎู: {user_audio}")
|
| 71 |
-
print(f"[๐ผ๏ธ] ู
ูู ุงูุตูุฑุฉ ุงูู
ูุฏุฎูุฉ: {user_image}")
|
| 72 |
-
|
| 73 |
print("๐ค ุชุญููู ุงูุตูุช ุฅูู ูุต...")
|
| 74 |
user_text = speech_to_text(user_audio)
|
| 75 |
-
print(f"[๐] ุงููุต ุงูู
ุณุชุฎุฑุฌ ู
ู ุงูุตูุช: {user_text}")
|
| 76 |
|
| 77 |
print("๐ฌ ุชูููุฏ ุงูุฑุฏ...")
|
| 78 |
reply = generate_reply(user_text)
|
| 79 |
-
print(f"[๐ค] ุงูุฑุฏ ุงูู
ูููุฏ: {reply}")
|
| 80 |
|
| 81 |
print("๐ ุชุญููู ุงูุฑุฏ ุฅูู ุตูุช...")
|
| 82 |
reply_audio_path = generate_voice(reply)
|
| 83 |
-
print(f"[๐] ู
ุณุงุฑ ุงูุตูุช ุงูู
ูููุฏ: {reply_audio_path}")
|
| 84 |
|
| 85 |
print("๐ฝ๏ธ ุชูููุฏ ุงูููุฏูู...")
|
| 86 |
Path("./output").mkdir(parents=True, exist_ok=True)
|
|
@@ -90,7 +87,6 @@ def full_pipeline(user_audio, user_image):
|
|
| 90 |
prompt=reply
|
| 91 |
)
|
| 92 |
|
| 93 |
-
print(f"[โ
] full_pipeline() ุงูุชููุ ุงูููุฏูู ุงูููุงุฆู ููุง: {video_path}")
|
| 94 |
return user_text, reply, reply_audio_path, video_path
|
| 95 |
|
| 96 |
# โ
ูุงุฌูุฉ Gradio
|
|
@@ -114,5 +110,3 @@ with gr.Blocks(title="๐ง ุตูุชู ูุญุฑู ุตูุฑุฉ!") as demo:
|
|
| 114 |
outputs=[user_text, reply_text, reply_audio, video_output])
|
| 115 |
|
| 116 |
demo.launch(inbrowser=True, share=True)
|
| 117 |
-
|
| 118 |
-
|
|
|
|
| 1 |
import subprocess
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
+
import shutil
|
| 5 |
from pathlib import Path
|
| 6 |
import argparse
|
| 7 |
import gradio as gr
|
| 8 |
|
| 9 |
+
# โ
ุงูุชูุธูู ุฃููุงู: ููุท ููู
ุฌูุฏุงุช ุงูู
ุคูุชุฉ
|
| 10 |
+
folders_to_delete = ["./output", "./__pycache__", "./.cache", "./temp"]
|
| 11 |
+
for folder in folders_to_delete:
|
| 12 |
+
if os.path.exists(folder):
|
| 13 |
+
print(f"๐๏ธ ุญุฐู {folder}")
|
| 14 |
+
shutil.rmtree(folder)
|
| 15 |
+
|
| 16 |
+
# โ
ุทุจุงุนุฉ ุญุงูุฉ ุงูุฐุงูุฑุฉ
|
| 17 |
+
import psutil
|
| 18 |
+
mem = psutil.virtual_memory()
|
| 19 |
+
print(f"๐ RAM ุงูู
ุณุชุฎุฏู
ุฉ: {mem.used / 1e9:.2f} GB / {mem.total / 1e9:.2f} GB")
|
| 20 |
+
|
| 21 |
+
# โ
ุชุญู
ูู ุงูู
ูุฏููุงุช ุฅุฐุง ู
ุง ูุงูุช ู
ูุฌูุฏุฉ
|
| 22 |
if not os.path.exists("./models/fantasytalking_model.ckpt"):
|
| 23 |
print("๐ ๏ธ ุฌุงุฑู ุชุญู
ูู ุงููู
ุงุฐุฌ ุนุจุฑ download_models.py ...")
|
| 24 |
subprocess.run(["python", "download_models.py"])
|
|
|
|
| 32 |
from TTS_X.tts import generate_voice
|
| 33 |
from FantasyTalking.infer import load_models, main
|
| 34 |
|
| 35 |
+
# โ
ุซุงุจุชุงุช ุงููู
ูุฐุฌ
|
| 36 |
args_template = argparse.Namespace(
|
| 37 |
fantasytalking_model_path="./models/fantasytalking_model.ckpt",
|
| 38 |
wav2vec_model_dir="./models/wav2vec2-base-960h",
|
| 39 |
+
wan_model_dir="./models/Wan2.1-I2V-14B-720P",
|
| 40 |
image_path="",
|
| 41 |
audio_path="",
|
| 42 |
prompt="",
|
| 43 |
output_dir="./output",
|
| 44 |
+
image_size=512,
|
| 45 |
audio_scale=1.0,
|
| 46 |
+
prompt_cfg_scale=5.0,
|
| 47 |
+
audio_cfg_scale=5.0,
|
| 48 |
+
max_num_frames=81,
|
| 49 |
+
inference_steps=20,
|
| 50 |
+
fps=23,
|
| 51 |
num_persistent_param_in_dit=None,
|
| 52 |
seed=1111
|
| 53 |
)
|
|
|
|
| 57 |
pipe, fantasytalking, wav2vec_processor, wav2vec = load_models(args_template)
|
| 58 |
print("โ
ุชู
ุงูุชุญู
ูู!")
|
| 59 |
|
| 60 |
+
# โ
ุชูููุฏ ููุฏูู
|
| 61 |
def generate_video(image_path, audio_path, prompt, output_dir="./output"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
args = argparse.Namespace(
|
| 63 |
**vars(args_template),
|
| 64 |
image_path=image_path,
|
|
|
|
| 66 |
prompt=prompt,
|
| 67 |
output_dir=output_dir
|
| 68 |
)
|
| 69 |
+
return main(args, pipe, fantasytalking, wav2vec_processor, wav2vec)
|
| 70 |
|
| 71 |
+
# โ
ุฎุท ุงูุฃูุงุจูุจ ุงููุงู
ู
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
def full_pipeline(user_audio, user_image):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
print("๐ค ุชุญููู ุงูุตูุช ุฅูู ูุต...")
|
| 74 |
user_text = speech_to_text(user_audio)
|
|
|
|
| 75 |
|
| 76 |
print("๐ฌ ุชูููุฏ ุงูุฑุฏ...")
|
| 77 |
reply = generate_reply(user_text)
|
|
|
|
| 78 |
|
| 79 |
print("๐ ุชุญููู ุงูุฑุฏ ุฅูู ุตูุช...")
|
| 80 |
reply_audio_path = generate_voice(reply)
|
|
|
|
| 81 |
|
| 82 |
print("๐ฝ๏ธ ุชูููุฏ ุงูููุฏูู...")
|
| 83 |
Path("./output").mkdir(parents=True, exist_ok=True)
|
|
|
|
| 87 |
prompt=reply
|
| 88 |
)
|
| 89 |
|
|
|
|
| 90 |
return user_text, reply, reply_audio_path, video_path
|
| 91 |
|
| 92 |
# โ
ูุงุฌูุฉ Gradio
|
|
|
|
| 110 |
outputs=[user_text, reply_text, reply_audio, video_output])
|
| 111 |
|
| 112 |
demo.launch(inbrowser=True, share=True)
|
|
|
|
|
|