sanchit-gandhi commited on
Commit
3167409
·
1 Parent(s): 00e31d2

file limit

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -13,7 +13,7 @@ from transformers.pipelines.audio_utils import ffmpeg_read
13
 
14
  title = "Whisper JAX: The Fastest Whisper API ⚡️"
15
 
16
- description = "Whisper JAX is an optimised implementation of the [Whisper model](https://huggingface.co/openai/whisper-large-v2) by OpenAI. It runs on JAX with a TPU v4-8 in the backend. Compared to PyTorch on an A100 GPU, it is over [**70x** faster](https://github.com/sanchit-gandhi/whisper-jax#benchmarks), making it the fastest Whisper API available."
17
 
18
  API_URL = os.getenv("API_URL")
19
  API_URL_FROM_FEATURES = os.getenv("API_URL_FROM_FEATURES")
@@ -24,6 +24,7 @@ language_names = sorted(TO_LANGUAGE_CODE.keys())
24
  CHUNK_LENGTH_S = 30
25
  BATCH_SIZE = 16
26
  NUM_PROC = 8
 
27
 
28
 
29
  def query(payload):
@@ -81,10 +82,14 @@ if __name__ == "__main__":
81
  )
82
 
83
  elif (microphone is None) and (file_upload is None):
84
- return "ERROR: You have to either use the microphone or upload an audio file"
85
 
86
  inputs = microphone if microphone is not None else file_upload
87
 
 
 
 
 
88
  with open(inputs, "rb") as f:
89
  inputs = f.read()
90
 
 
13
 
14
  title = "Whisper JAX: The Fastest Whisper API ⚡️"
15
 
16
+ description = "Whisper JAX is an optimised implementation of the [Whisper model](https://huggingface.co/openai/whisper-large-v2) by OpenAI. It runs on JAX with a TPU v4-8 in the backend. Compared to PyTorch on an A100 GPU, it is over [**70x faster**](https://github.com/sanchit-gandhi/whisper-jax#benchmarks), making it the fastest Whisper API available."
17
 
18
  API_URL = os.getenv("API_URL")
19
  API_URL_FROM_FEATURES = os.getenv("API_URL_FROM_FEATURES")
 
24
  CHUNK_LENGTH_S = 30
25
  BATCH_SIZE = 16
26
  NUM_PROC = 8
27
+ FILE_LIMIT_MB = 50
28
 
29
 
30
  def query(payload):
 
82
  )
83
 
84
  elif (microphone is None) and (file_upload is None):
85
+ return "ERROR: You have to either use the microphone or upload an audio file", None
86
 
87
  inputs = microphone if microphone is not None else file_upload
88
 
89
+ file_size_mb = os.stat(inputs).st_size / (1024 * 1024)
90
+ if file_size_mb > FILE_LIMIT_MB:
91
+ return f"ERROR: File size exceeds file size limit. Got file of size {file_size_mb}MB for a limit of {FILE_LIMIT_MB}MB.", None
92
+
93
  with open(inputs, "rb") as f:
94
  inputs = f.read()
95