yuangongfdu commited on
Commit
bfe831e
1 Parent(s): 7a2502d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -1,9 +1,24 @@
1
  import json
2
  import gradio as gr
3
  import requests
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  def upload_audio(audio_path):
6
  try:
 
 
 
7
  with open(audio_path, 'rb') as audio_file:
8
  response = requests.post('http://sls-titan-6.csail.mit.edu:8080/upload/', files={'audio_file': audio_file})
9
  if response.status_code == 200:
@@ -15,6 +30,8 @@ def predict(audio_path, question):
15
  upload_statues = upload_audio(audio_path)
16
  if upload_statues == None:
17
  return 'Please upload an audio file.'
 
 
18
  if question == '':
19
  return 'Please ask a question.'
20
  print(audio_path, question)
@@ -42,6 +59,6 @@ if __name__ == '__main__':
42
  description="LTU-2 an improved version of LTU. LTU-2 is stronger in spoken text understanding and music understanding. <br>" +
43
  "LTU is authored by Yuan Gong, Alexander H. Liu, Hongyin Luo, Leonid Karlinsky, and James Glass (MIT & MIT-IBM Watson AI Lab). <br>" +
44
  "**Please note that the model is under construction and may be buggy. It is trained with some new techniques that are not described in LTU paper. I.e., using method described in LTU paper cannot reproduce this model.**<br>" +
45
- "Input should be wav file sampled at 16kHz. This demo trim input audio to 10 seconds."
46
  "**Research Demo, No Commercial Use (Due to license of LLaMA).**")
47
  demo.launch(debug=False, share=False)
 
1
  import json
2
  import gradio as gr
3
  import requests
4
+ import os
5
+
6
+ def is_file_larger_than_30mb(file_path):
7
+ try:
8
+ file_size = os.path.getsize(file_path)
9
+ return file_size > (30 * 1024 * 1024)
10
+ except FileNotFoundError:
11
+ return False
12
+ except PermissionError:
13
+ return False
14
+ except Exception as e:
15
+ return False
16
 
17
  def upload_audio(audio_path):
18
  try:
19
+ size = is_file_larger_than_30mb(audio_path)
20
+ if size == True:
21
+ return 'size'
22
  with open(audio_path, 'rb') as audio_file:
23
  response = requests.post('http://sls-titan-6.csail.mit.edu:8080/upload/', files={'audio_file': audio_file})
24
  if response.status_code == 200:
 
30
  upload_statues = upload_audio(audio_path)
31
  if upload_statues == None:
32
  return 'Please upload an audio file.'
33
+ if upload_statues == 'size':
34
+ return 'This demo does not support audio file size larger than 30MB.'
35
  if question == '':
36
  return 'Please ask a question.'
37
  print(audio_path, question)
 
59
  description="LTU-2 an improved version of LTU. LTU-2 is stronger in spoken text understanding and music understanding. <br>" +
60
  "LTU is authored by Yuan Gong, Alexander H. Liu, Hongyin Luo, Leonid Karlinsky, and James Glass (MIT & MIT-IBM Watson AI Lab). <br>" +
61
  "**Please note that the model is under construction and may be buggy. It is trained with some new techniques that are not described in LTU paper. I.e., using method described in LTU paper cannot reproduce this model.**<br>" +
62
+ "Input should be wav file sampled at 16kHz. This demo trim input audio to 10 seconds. <br>"
63
  "**Research Demo, No Commercial Use (Due to license of LLaMA).**")
64
  demo.launch(debug=False, share=False)