huedaya commited on
Commit
b3b871d
·
1 Parent(s): 2159625
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -5,8 +5,9 @@ import whisper
5
  from flask import Flask, jsonify, request
6
  import requests
7
  import time
 
8
 
9
- model = whisper.load_model("medium")
10
 
11
  app = Flask(__name__)
12
  app.config['TIMEOUT'] = 60 * 10 # 10 mins
@@ -23,6 +24,13 @@ def runApi():
23
 
24
  response = requests.get(audio_url)
25
 
 
 
 
 
 
 
 
26
  if response.status_code == requests.codes.ok:
27
  with open("audio.mp3", "wb") as f:
28
  f.write(response.content)
@@ -35,15 +43,16 @@ def runApi():
35
  audio = "audio.mp3"
36
 
37
  audio = whisper.load_audio(audio)
38
- audio = whisper.pad_or_trim(audio)
39
 
40
- mel = whisper.log_mel_spectrogram(audio).to(model.device)
41
 
42
- _, probs = model.detect_language(mel)
43
 
44
- options = whisper.DecodingOptions(fp16 = False)
45
- result = whisper.decode(model, mel, options)
46
 
 
47
 
48
  end_time = time.time()
49
  total_time = end_time - start_time
 
5
  from flask import Flask, jsonify, request
6
  import requests
7
  import time
8
+ from transformers import pipeline
9
 
10
+ model = whisper.load_model("small")
11
 
12
  app = Flask(__name__)
13
  app.config['TIMEOUT'] = 60 * 10 # 10 mins
 
24
 
25
  response = requests.get(audio_url)
26
 
27
+ pipe = pipeline(
28
+ "automatic-speech-recognition",
29
+ model="openai/whisper-large",
30
+ chunk_length_s=30,
31
+ device=model.device,
32
+ )
33
+
34
  if response.status_code == requests.codes.ok:
35
  with open("audio.mp3", "wb") as f:
36
  f.write(response.content)
 
43
  audio = "audio.mp3"
44
 
45
  audio = whisper.load_audio(audio)
46
+ # audio = whisper.pad_or_trim(audio)
47
 
48
+ # mel = whisper.log_mel_spectrogram(audio).to(model.device)
49
 
50
+ # _, probs = model.detect_language(mel)
51
 
52
+ # options = whisper.DecodingOptions(fp16 = False)
53
+ # result = whisper.decode(model, mel, options)
54
 
55
+ result = pipe(audio.copy())["text"]
56
 
57
  end_time = time.time()
58
  total_time = end_time - start_time