zinoubm commited on
Commit
1a81701
·
1 Parent(s): 4f8f8b7

adding comments and cleaning app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -8,6 +8,9 @@ openai.api_key = OPENAI_API_KEY
8
 
9
 
10
  def get_command(command, model, id2label):
 
 
 
11
  completion = openai.Completion.create(
12
  model=model, prompt=f"{command}->", max_tokens=1, temperature=0
13
  )
@@ -17,20 +20,28 @@ def get_command(command, model, id2label):
17
 
18
 
19
  def transcribe(audio, text):
 
 
 
 
 
20
  if text:
21
  result = get_command(text, MODEL, id2label)
22
  return "Text provided by the user", text_respnses[result], None
23
 
24
- input, rate = librosa.load(
25
- audio, sr=16000
26
- ) # Downsample original frequency to 16000hrz
 
27
  inputs = processor(input, sampling_rate=rate, return_tensors="pt")
28
  generated_ids = model.generate(
29
  inputs["input_features"], attention_mask=inputs["attention_mask"]
30
  )
 
31
  transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)
32
  result = get_command(transcription, MODEL, id2label)
33
  audio_res = resoponses.get(result)()
 
34
  return transcription, text_respnses[result], audio_res
35
 
36
 
 
8
 
9
 
10
  def get_command(command, model, id2label):
11
+ """
12
+ This function get the classification outputs from openai API
13
+ """
14
  completion = openai.Completion.create(
15
  model=model, prompt=f"{command}->", max_tokens=1, temperature=0
16
  )
 
20
 
21
 
22
  def transcribe(audio, text):
23
+ """
24
+ if text provided the function will classify the input directly.
25
+ if not the audio will be transcribed then the transcription will be classified.
26
+ """
27
+
28
  if text:
29
  result = get_command(text, MODEL, id2label)
30
  return "Text provided by the user", text_respnses[result], None
31
 
32
+ # Downsample original frequency to 16000hrz
33
+ input, rate = librosa.load(audio, sr=16000)
34
+
35
+ # getting text transcription
36
  inputs = processor(input, sampling_rate=rate, return_tensors="pt")
37
  generated_ids = model.generate(
38
  inputs["input_features"], attention_mask=inputs["attention_mask"]
39
  )
40
+
41
  transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)
42
  result = get_command(transcription, MODEL, id2label)
43
  audio_res = resoponses.get(result)()
44
+
45
  return transcription, text_respnses[result], audio_res
46
 
47