Daryl Fung commited on
Commit
59da368
1 Parent(s): 0309473

added batch

Browse files
Files changed (2) hide show
  1. app.py +0 -2
  2. db/make_audio.py +13 -5
app.py CHANGED
@@ -10,8 +10,6 @@ index.add(model.encode(['hello']))
10
 
11
  app = FastAPI()
12
 
13
-
14
-
15
  @app.post('/tts')
16
  async def transcribe(text: str):
17
  embeddings = model.encode([text])
 
10
 
11
  app = FastAPI()
12
 
 
 
13
  @app.post('/tts')
14
  async def transcribe(text: str):
15
  embeddings = model.encode([text])
db/make_audio.py CHANGED
@@ -21,6 +21,9 @@ async def make_audio():
21
 
22
  response_iterator = response.query_iterator(batch_size=1, output_fields=['text', 'embeddings'])
23
  ids_to_delete = []
 
 
 
24
  while True:
25
  res = response_iterator.next()
26
  if len(res) == 0:
@@ -43,13 +46,18 @@ async def make_audio():
43
  data.append([res[0]['text'], uploaded_object.obj_id, res[0]['embeddings']])
44
  ids_to_delete.append(res[0]['id'])
45
 
46
- audio_response.insert(list(zip(*data)))
47
- audio_response.flush()
48
 
49
- # delete text to generate audio
50
- response.delete(expr=f"id in {str(ids_to_delete)}")
51
- response_iterator.close()
 
52
 
 
 
 
 
 
53
 
54
  if __name__ == '__main__':
55
  loop = asyncio.new_event_loop()
 
21
 
22
  response_iterator = response.query_iterator(batch_size=1, output_fields=['text', 'embeddings'])
23
  ids_to_delete = []
24
+ current_iteration = 0
25
+ batch_size = 5
26
+
27
  while True:
28
  res = response_iterator.next()
29
  if len(res) == 0:
 
46
  data.append([res[0]['text'], uploaded_object.obj_id, res[0]['embeddings']])
47
  ids_to_delete.append(res[0]['id'])
48
 
49
+ current_iteration += 1
 
50
 
51
+ if current_iteration % batch_size == 0:
52
+ # insert the audio
53
+ audio_response.insert(list(zip(*data)))
54
+ audio_response.flush()
55
 
56
+ # delete text to generate audio
57
+ response.delete(expr=f"id in {str(ids_to_delete)}")
58
+ ids_to_delete = []
59
+
60
+ response_iterator.close()
61
 
62
  if __name__ == '__main__':
63
  loop = asyncio.new_event_loop()