Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,26 +4,26 @@ import sys
|
|
| 4 |
from pathlib import Path
|
| 5 |
import argparse
|
| 6 |
import gradio as gr
|
| 7 |
-
# شغّلي السكربت إذا ما اشتغل قبل كذا
|
| 8 |
-
if not os.path.exists("./fantasy/fantasytalking_model.ckpt"):
|
| 9 |
-
print("🛠️ جاري تحميل الملفات عبر setup.sh ...")
|
| 10 |
-
subprocess.run(["bash", "setup.sh"])
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
# إعداد المسارات
|
| 15 |
sys.path.append(os.path.abspath("."))
|
| 16 |
|
| 17 |
-
# استيراد
|
| 18 |
from STT.sst import speech_to_text
|
| 19 |
from LLM.llm import generate_reply
|
| 20 |
from TTS_X.tts import generate_voice
|
| 21 |
from FantasyTalking.infer import load_models, main
|
| 22 |
|
| 23 |
-
# ثابتات النموذج
|
| 24 |
args_template = argparse.Namespace(
|
| 25 |
-
fantasytalking_model_path="./
|
| 26 |
-
wav2vec_model_dir="./
|
|
|
|
| 27 |
image_path="",
|
| 28 |
audio_path="",
|
| 29 |
prompt="",
|
|
@@ -39,11 +39,12 @@ args_template = argparse.Namespace(
|
|
| 39 |
seed=1111
|
| 40 |
)
|
| 41 |
|
| 42 |
-
# تحميل النماذج
|
| 43 |
print("🚀 جاري تحميل FantasyTalking و Wav2Vec...")
|
| 44 |
pipe, fantasytalking, wav2vec_processor, wav2vec = load_models(args_template)
|
| 45 |
print("✅ تم التحميل!")
|
| 46 |
|
|
|
|
| 47 |
def generate_video(image_path, audio_path, prompt, output_dir="./output"):
|
| 48 |
args = argparse.Namespace(
|
| 49 |
**vars(args_template),
|
|
@@ -54,6 +55,7 @@ def generate_video(image_path, audio_path, prompt, output_dir="./output"):
|
|
| 54 |
)
|
| 55 |
return main(args, pipe, fantasytalking, wav2vec_processor, wav2vec)
|
| 56 |
|
|
|
|
| 57 |
def full_pipeline(user_audio, user_image):
|
| 58 |
print("🎤 تحويل الصوت إلى نص...")
|
| 59 |
user_text = speech_to_text(user_audio)
|
|
@@ -74,7 +76,7 @@ def full_pipeline(user_audio, user_image):
|
|
| 74 |
|
| 75 |
return user_text, reply, reply_audio_path, video_path
|
| 76 |
|
| 77 |
-
# واجهة Gradio
|
| 78 |
with gr.Blocks(title="🧠 صوتك يحرك صورة!") as demo:
|
| 79 |
gr.Markdown("## 🎤➡️💬➡️🔊➡️📽️ من صوتك إلى فيديو متكلم!")
|
| 80 |
|
|
@@ -95,4 +97,3 @@ with gr.Blocks(title="🧠 صوتك يحرك صورة!") as demo:
|
|
| 95 |
outputs=[user_text, reply_text, reply_audio, video_output])
|
| 96 |
|
| 97 |
demo.launch(inbrowser=True, share=True)
|
| 98 |
-
|
|
|
|
| 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"])
|
| 12 |
|
| 13 |
+
# ✅ إعداد المسارات للمشروع
|
|
|
|
| 14 |
sys.path.append(os.path.abspath("."))
|
| 15 |
|
| 16 |
+
# ✅ استيراد المكونات
|
| 17 |
from STT.sst import speech_to_text
|
| 18 |
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", # لو رجعتي تستخدمي Wan
|
| 27 |
image_path="",
|
| 28 |
audio_path="",
|
| 29 |
prompt="",
|
|
|
|
| 39 |
seed=1111
|
| 40 |
)
|
| 41 |
|
| 42 |
+
# ✅ تحميل النماذج
|
| 43 |
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),
|
|
|
|
| 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)
|
|
|
|
| 76 |
|
| 77 |
return user_text, reply, reply_audio_path, video_path
|
| 78 |
|
| 79 |
+
# ✅ واجهة Gradio
|
| 80 |
with gr.Blocks(title="🧠 صوتك يحرك صورة!") as demo:
|
| 81 |
gr.Markdown("## 🎤➡️💬➡️🔊➡️📽️ من صوتك إلى فيديو متكلم!")
|
| 82 |
|
|
|
|
| 97 |
outputs=[user_text, reply_text, reply_audio, video_output])
|
| 98 |
|
| 99 |
demo.launch(inbrowser=True, share=True)
|
|
|