Athagi commited on
Commit
29c9c4c
·
verified ·
1 Parent(s): 3800f2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -6,22 +6,22 @@ import numpy as np
6
  import soundfile as sf
7
  import requests
8
 
9
- # ========== DOWNLOAD PRETRAINED MODEL ==========
 
10
  MODEL_PATH = "model/D_v13_20231020.pth"
11
  os.makedirs("model", exist_ok=True)
12
 
13
  def download_model():
14
  if not os.path.exists(MODEL_PATH):
15
- url = "https://huggingface.co/MMVC/prelearned-model/resolve/main/D_v13_20231020.pth"
16
  print("Downloading model...")
17
- response = requests.get(url)
18
  with open(MODEL_PATH, "wb") as f:
19
  f.write(response.content)
20
  print("Model downloaded.")
21
 
22
  download_model()
23
 
24
- # ========== DUMMY MODEL LOADER (Placeholder for real MMVC model) ==========
25
  class DummyVoiceChanger(torch.nn.Module):
26
  def __init__(self):
27
  super().__init__()
@@ -29,14 +29,13 @@ class DummyVoiceChanger(torch.nn.Module):
29
 
30
  def forward(self, audio):
31
  audio = torch.tensor(audio, dtype=torch.float32)
32
- return (audio * self.gain).numpy()
33
 
34
- # Load dummy model
35
  model = DummyVoiceChanger()
36
- state_dict = torch.load(MODEL_PATH, map_location="cpu")
37
- # model.load_state_dict(state_dict) # Skip loading for this dummy model
38
 
39
- # ========== VOICE CONVERSION FUNCTION ==========
40
  def convert_voice(audio_file):
41
  audio_data, sr = librosa.load(audio_file, sr=16000)
42
  audio_data = librosa.util.fix_length(audio_data, size=16000 * 5)
@@ -53,8 +52,8 @@ interface = gr.Interface(
53
  fn=convert_voice,
54
  inputs=gr.Audio(type="filepath", label="Upload Voice"),
55
  outputs=gr.Audio(type="filepath", label="Converted Voice"),
56
- title="AI Voice Changer (No RVC / No TTS)",
57
- description="Uploads a voice file, downloads AI model, and changes the voice using PyTorch. Replace dummy model with real MMVC inference logic for full functionality."
58
  )
59
 
60
  interface.launch()
 
6
  import soundfile as sf
7
  import requests
8
 
9
+ # ========== MODEL SETUP ==========
10
+ MODEL_URL = "https://huggingface.co/MMVC/prelearned-model/resolve/main/D_v13_20231020.pth"
11
  MODEL_PATH = "model/D_v13_20231020.pth"
12
  os.makedirs("model", exist_ok=True)
13
 
14
  def download_model():
15
  if not os.path.exists(MODEL_PATH):
 
16
  print("Downloading model...")
17
+ response = requests.get(MODEL_URL)
18
  with open(MODEL_PATH, "wb") as f:
19
  f.write(response.content)
20
  print("Model downloaded.")
21
 
22
  download_model()
23
 
24
+ # ========== DUMMY VOICE CHANGER MODEL ==========
25
  class DummyVoiceChanger(torch.nn.Module):
26
  def __init__(self):
27
  super().__init__()
 
29
 
30
  def forward(self, audio):
31
  audio = torch.tensor(audio, dtype=torch.float32)
32
+ return (audio * self.gain).detach().numpy() # FIXED
33
 
 
34
  model = DummyVoiceChanger()
35
+ # Skipping real loading of .pth, as it's just a placeholder
36
+ # torch.load(MODEL_PATH) would load it here if needed
37
 
38
+ # ========== INFERENCE FUNCTION ==========
39
  def convert_voice(audio_file):
40
  audio_data, sr = librosa.load(audio_file, sr=16000)
41
  audio_data = librosa.util.fix_length(audio_data, size=16000 * 5)
 
52
  fn=convert_voice,
53
  inputs=gr.Audio(type="filepath", label="Upload Voice"),
54
  outputs=gr.Audio(type="filepath", label="Converted Voice"),
55
+ title="🗣️ AI Voice Changer (No RVC / No TTS)",
56
+ description="Simple PyTorch voice changer using a dummy model and direct model download. Replace dummy model with real MMVC for production."
57
  )
58
 
59
  interface.launch()