Qa5im commited on
Commit
131efd5
·
1 Parent(s): 88a452b

updated server file to fix recorded files pro

Browse files
Files changed (1) hide show
  1. server.py +32 -26
server.py CHANGED
@@ -14,7 +14,6 @@ import glob
14
 
15
  UPLOAD_DIR = Path() / "uploads"
16
  UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
17
- os.environ[ 'NUMBA_CACHE_DIR' ] = '/tmp/'
18
 
19
  app = FastAPI()
20
 
@@ -39,31 +38,37 @@ def delFiles():
39
 
40
 
41
  async def predictor(names, file_uploads, usersNum, recordingsNum):
42
- speaker_embed_list = []
43
- encoder = VoiceEncoder()
44
- # Iterating over list of files corresponding to each user
45
- speaker_wavs_list = []
46
- fileInd = 0
47
- names.pop() # to remove key named "test"
48
- for name in names:
49
- wav_fpaths = []
50
- for ind in range(int(recordingsNum)):
51
- file_upload = file_uploads[fileInd]
52
- data = await file_upload.read()
53
- # appending person's name to the his/her recordings
54
- filename = name+"¬"+file_upload.filename
55
- file_path = UPLOAD_DIR / filename
56
- with open(file_path, "wb") as file_object:
57
- file_object.write(data)
58
- wav_fpaths.append(Path(file_path))
59
- fileInd += 1
60
- try:
61
- speaker_wavs = {speaker: list(map(preprocess_wav, wav_fpaths)) for speaker, wav_fpaths in
62
- groupby(tqdm(wav_fpaths, "Preprocessing wavs", len(wav_fpaths), unit="wavs"),
63
- lambda wav_fpath: os.path.basename(wav_fpath).split("¬")[0])} # extracting person's name from file name
64
- speaker_wavs_list.append(speaker_wavs)
65
- except Exception as e:
66
- print("error ", e)
 
 
 
 
 
 
67
 
68
  # make a list of the pre-processed audios ki arrays
69
  for sp_wvs in speaker_wavs_list:
@@ -80,6 +85,7 @@ async def predictor(names, file_uploads, usersNum, recordingsNum):
80
  with open(file_path, "wb") as file_object:
81
  file_object.write(data)
82
  wav_fpaths.append(Path(file_path))
 
83
  test_pos_wavs = {speaker: list(map(preprocess_wav, wav_fpaths)) for speaker, wav_fpaths in
84
  groupby(tqdm(wav_fpaths, "Preprocessing wavs", len(wav_fpaths), unit="wavs"),
85
  lambda wav_fpath: "test")}
 
14
 
15
  UPLOAD_DIR = Path() / "uploads"
16
  UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
 
17
 
18
  app = FastAPI()
19
 
 
38
 
39
 
40
  async def predictor(names, file_uploads, usersNum, recordingsNum):
41
+ try:
42
+ speaker_embed_list = []
43
+ encoder = VoiceEncoder()
44
+ # Iterating over list of files corresponding to each user
45
+ speaker_wavs_list = []
46
+ fileInd = 0
47
+ names.pop() # to remove key named "test"
48
+ print("file_uploads ", file_uploads, "recordingNums ", recordingsNum)
49
+ for name in names:
50
+ wav_fpaths = []
51
+ for ind in range(int(recordingsNum)):
52
+ print("inside yo")
53
+ file_upload = file_uploads[fileInd]
54
+ data = await file_upload.read()
55
+ # appending person's name to the his/her recordings
56
+ filename = name+"¬"+file_upload.filename
57
+ file_path = UPLOAD_DIR / filename
58
+ with open(file_path, "wb") as file_object:
59
+ file_object.write(data)
60
+ wav_fpaths.append(Path(file_path))
61
+ fileInd += 1
62
+ print("wav_fpaths len", len(wav_fpaths), "name", name)
63
+ try:
64
+ speaker_wavs = {speaker: list(map(preprocess_wav, wav_fpaths)) for speaker, wav_fpaths in
65
+ groupby(tqdm(wav_fpaths, "Preprocessing wavs", len(wav_fpaths), unit="wavs"),
66
+ lambda wav_fpath: os.path.basename(wav_fpath).split("¬")[0])} # extracting person's name from file name
67
+ speaker_wavs_list.append(speaker_wavs)
68
+ except Exception as e:
69
+ print("error ", e)
70
+ except Exception as e:
71
+ print("function error ", e)
72
 
73
  # make a list of the pre-processed audios ki arrays
74
  for sp_wvs in speaker_wavs_list:
 
85
  with open(file_path, "wb") as file_object:
86
  file_object.write(data)
87
  wav_fpaths.append(Path(file_path))
88
+ print("about to test\n")
89
  test_pos_wavs = {speaker: list(map(preprocess_wav, wav_fpaths)) for speaker, wav_fpaths in
90
  groupby(tqdm(wav_fpaths, "Preprocessing wavs", len(wav_fpaths), unit="wavs"),
91
  lambda wav_fpath: "test")}