File size: 2,303 Bytes
f5790af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import torch
import torch.nn as nn
import wget
import os

LIPSYNC_FOLDER = "./LipSyncModel"
LIPSYNC_MODEL_WEIGHTS = "lipsync_expert.pth"
LIPSYNC_MODEL_WEIGHTS_URL = "https://iiitaphyd-my.sharepoint.com/personal/radrabha_m_research_iiit_ac_in/_layouts/15/download.aspx?SourceUrl=%2Fpersonal%2Fradrabha%5Fm%5Fresearch%5Fiiit%5Fac%5Fin%2FDocuments%2FWav2Lip%5FModels%2Flipsync%5Fexpert%2Epth"
LIPSYNC_FILES_URLS = [
    (LIPSYNC_MODEL_WEIGHTS_URL, LIPSYNC_MODEL_WEIGHTS),
]

WAV2LIP_FOLDER = "./Wav2LipModel"
WAV2LIP_MODEL_WEIGHTS = "wav2lip_gan.pth"
WAV2LIP_MODEL_WEIGHTS_URL = "https://iiitaphyd-my.sharepoint.com/personal/radrabha_m_research_iiit_ac_in/_layouts/15/download.aspx?SourceUrl=%2Fpersonal%2Fradrabha%5Fm%5Fresearch%5Fiiit%5Fac%5Fin%2FDocuments%2FWav2Lip%5FModels%2Fwav2lip%5Fgan%2Epth"
WAV2LIP_FILES_URLS = [
    (WAV2LIP_MODEL_WEIGHTS_URL, WAV2LIP_MODEL_WEIGHTS),
]

def ensure_lipsync_files_exist():
    os.makedirs(LIPSYNC_FOLDER, exist_ok=True)
    for url, filename in LIPSYNC_FILES_URLS:
        filepath = os.path.join(LIPSYNC_FOLDER, filename)
        if not os.path.exists(filepath):
            try:
                wget.download(url, out=filepath)
            except Exception as e:
                print(f"Warning: Download for {filename} failed, likely due to link restrictions. You may need to download it manually.")

def ensure_wav2lip_files_exist():
    os.makedirs(WAV2LIP_FOLDER, exist_ok=True)
    for url, filename in WAV2LIP_FILES_URLS:
        filepath = os.path.join(WAV2LIP_FOLDER, filename)
        if not os.path.exists(filepath):
            try:
                wget.download(url, out=filepath)
            except Exception as e:
                print(f"Warning: Download for {filename} failed, likely due to link restrictions. You may need to download it manually.")


class LipSyncModel(nn.Module):
    def __init__(self, num_classes):
        super().__init__()
        self.fc = nn.Linear(100, num_classes)

    def forward(self, x):
        logits = self.fc(x)
        return logits

class Wav2LipModel(nn.Module):
    def __init__(self, num_classes):
        super().__init__()
        self.fc = nn.Linear(100, num_classes)

    def forward(self, x):
        logits = self.fc(x)
        return logits