Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,13 +3,13 @@ import zipfile
|
|
| 3 |
import subprocess
|
| 4 |
import gradio as gr
|
| 5 |
from tortoise.api import TextToSpeech
|
| 6 |
-
|
| 7 |
|
| 8 |
# Paths
|
| 9 |
-
ZIP_FILE = "Trump-LipSync.zip"
|
| 10 |
-
EXTRACTED_FOLDER = "Trump-LipSync"
|
| 11 |
-
TRUMP_VIDEO_PATH = os.path.join(EXTRACTED_FOLDER, "videos", "trump.mp4")
|
| 12 |
-
CHECKPOINT_PATH = os.path.join(EXTRACTED_FOLDER, "Wav2Lip", "checkpoints", "wav2lip_gan.pth")
|
| 13 |
|
| 14 |
# Function to extract the zip file
|
| 15 |
def extract_zip():
|
|
@@ -34,9 +34,16 @@ def extract_zip():
|
|
| 34 |
def generate_speech(text, output_wav):
|
| 35 |
try:
|
| 36 |
tts = TextToSpeech()
|
| 37 |
-
|
| 38 |
speech = tts.tts(text, "trump")
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
return True
|
| 41 |
except Exception as e:
|
| 42 |
print(f"Error generating speech: {str(e)}")
|
|
@@ -58,7 +65,6 @@ def run_wav2lip(video_path, audio_path, output_video):
|
|
| 58 |
print(f"Error running Wav2Lip: {str(e)}")
|
| 59 |
return False
|
| 60 |
|
| 61 |
-
# Function to handle the lip-sync pipeline
|
| 62 |
def process_lipsync(text):
|
| 63 |
try:
|
| 64 |
# Check if the zip file is extracted
|
|
|
|
| 3 |
import subprocess
|
| 4 |
import gradio as gr
|
| 5 |
from tortoise.api import TextToSpeech
|
| 6 |
+
import torchaudio # Added import for torchaudio
|
| 7 |
|
| 8 |
# Paths
|
| 9 |
+
ZIP_FILE = "Trump-LipSync.zip"
|
| 10 |
+
EXTRACTED_FOLDER = "Trump-LipSync"
|
| 11 |
+
TRUMP_VIDEO_PATH = os.path.join(EXTRACTED_FOLDER, "videos", "trump.mp4")
|
| 12 |
+
CHECKPOINT_PATH = os.path.join(EXTRACTED_FOLDER, "Wav2Lip", "checkpoints", "wav2lip_gan.pth")
|
| 13 |
|
| 14 |
# Function to extract the zip file
|
| 15 |
def extract_zip():
|
|
|
|
| 34 |
def generate_speech(text, output_wav):
|
| 35 |
try:
|
| 36 |
tts = TextToSpeech()
|
| 37 |
+
|
| 38 |
speech = tts.tts(text, "trump")
|
| 39 |
+
|
| 40 |
+
speech = speech.squeeze()
|
| 41 |
+
if speech.dim() == 1:
|
| 42 |
+
speech = speech.unsqueeze(0)
|
| 43 |
+
|
| 44 |
+
sample_rate = 22050
|
| 45 |
+
torchaudio.save(output_wav, speech.cpu(), sample_rate)
|
| 46 |
+
|
| 47 |
return True
|
| 48 |
except Exception as e:
|
| 49 |
print(f"Error generating speech: {str(e)}")
|
|
|
|
| 65 |
print(f"Error running Wav2Lip: {str(e)}")
|
| 66 |
return False
|
| 67 |
|
|
|
|
| 68 |
def process_lipsync(text):
|
| 69 |
try:
|
| 70 |
# Check if the zip file is extracted
|