Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,12 +5,12 @@ 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"])
|
12 |
|
13 |
-
# โ
ุฅุนุฏุงุฏ ุงูู
ุณุงุฑุงุช
|
14 |
sys.path.append(os.path.abspath("."))
|
15 |
|
16 |
# โ
ุงุณุชูุฑุงุฏ ุงูู
ูููุงุช
|
@@ -19,11 +19,11 @@ 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="",
|
@@ -44,8 +44,14 @@ 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 |
args = argparse.Namespace(
|
50 |
**vars(args_template),
|
51 |
image_path=image_path,
|
@@ -53,18 +59,28 @@ def generate_video(image_path, audio_path, prompt, output_dir="./output"):
|
|
53 |
prompt=prompt,
|
54 |
output_dir=output_dir
|
55 |
)
|
56 |
-
return main(args, pipe, fantasytalking, wav2vec_processor, wav2vec)
|
57 |
|
58 |
-
|
|
|
|
|
|
|
|
|
59 |
def full_pipeline(user_audio, user_image):
|
|
|
|
|
|
|
|
|
60 |
print("๐ค ุชุญููู ุงูุตูุช ุฅูู ูุต...")
|
61 |
user_text = speech_to_text(user_audio)
|
|
|
62 |
|
63 |
print("๐ฌ ุชูููุฏ ุงูุฑุฏ...")
|
64 |
reply = generate_reply(user_text)
|
|
|
65 |
|
66 |
print("๐ ุชุญููู ุงูุฑุฏ ุฅูู ุตูุช...")
|
67 |
reply_audio_path = generate_voice(reply)
|
|
|
68 |
|
69 |
print("๐ฝ๏ธ ุชูููุฏ ุงูููุฏูู...")
|
70 |
Path("./output").mkdir(parents=True, exist_ok=True)
|
@@ -74,6 +90,7 @@ def full_pipeline(user_audio, user_image):
|
|
74 |
prompt=reply
|
75 |
)
|
76 |
|
|
|
77 |
return user_text, reply, reply_audio_path, video_path
|
78 |
|
79 |
# โ
ูุงุฌูุฉ Gradio
|
@@ -97,3 +114,5 @@ with gr.Blocks(title="๐ง ุตูุชู ูุญุฑู ุตูุฑุฉ!") as demo:
|
|
97 |
outputs=[user_text, reply_text, reply_audio, video_output])
|
98 |
|
99 |
demo.launch(inbrowser=True, share=True)
|
|
|
|
|
|
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"])
|
12 |
|
13 |
+
# โ
ุฅุนุฏุงุฏ ุงูู
ุณุงุฑุงุช
|
14 |
sys.path.append(os.path.abspath("."))
|
15 |
|
16 |
# โ
ุงุณุชูุฑุงุฏ ุงูู
ูููุงุช
|
|
|
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="",
|
|
|
44 |
pipe, fantasytalking, wav2vec_processor, wav2vec = load_models(args_template)
|
45 |
print("โ
ุชู
ุงูุชุญู
ูู!")
|
46 |
|
47 |
+
# โ
ุชูููุฏ ุงูููุฏูู - ู
ุน ุทุจุงุนุฉ Debug
|
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 |
prompt=prompt,
|
60 |
output_dir=output_dir
|
61 |
)
|
|
|
62 |
|
63 |
+
video_path = main(args, pipe, fantasytalking, wav2vec_processor, wav2vec)
|
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 |
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 |
outputs=[user_text, reply_text, reply_audio, video_output])
|
115 |
|
116 |
demo.launch(inbrowser=True, share=True)
|
117 |
+
|
118 |
+
|