Adityadn commited on
Commit
b90cfad
·
verified ·
1 Parent(s): e161859

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -11
app.py CHANGED
@@ -7,7 +7,7 @@ import shutil
7
  # Retrieve ACRCloud credentials from environment variables
8
  acr_access_key = os.environ.get('ACR_ACCESS_KEY')
9
  acr_access_secret = os.environ.get('ACR_ACCESS_SECRET')
10
- acr_host = os.environ.get('ACR_HOST', 'eu-west-1.api.acrcloud.com')
11
 
12
  # ACRCloud recognizer configuration
13
  config = {
@@ -21,13 +21,8 @@ config = {
21
  acr = ACRCloudRecognizer(config)
22
 
23
  def identify_audio(file):
24
- # Create a temporary file path
25
- temp_dir = tempfile.mkdtemp()
26
- file_path = os.path.join(temp_dir, file.name)
27
-
28
- # Open the uploaded file and save it to the temporary directory
29
- with open(file_path, 'wb') as f:
30
- f.write(file.read()) # Write the content of the uploaded file to disk
31
 
32
  # Get the duration of the audio file in milliseconds
33
  duration_ms = int(acr.get_duration_ms_by_file(file_path))
@@ -47,9 +42,6 @@ def identify_audio(file):
47
  buf = f.read()
48
  buffer_result = acr.recognize_by_filebuffer(buf, 0)
49
 
50
- # Clean up the temporary file
51
- shutil.rmtree(temp_dir)
52
-
53
  return {
54
  "Partial Results": results,
55
  "Full Result": full_result,
 
7
  # Retrieve ACRCloud credentials from environment variables
8
  acr_access_key = os.environ.get('ACR_ACCESS_KEY')
9
  acr_access_secret = os.environ.get('ACR_ACCESS_SECRET')
10
+ acr_host = 'identify-ap-southeast-1.acrcloud.com' # os.environ.get('ACR_HOST', 'eu-west-1.api.acrcloud.com')
11
 
12
  # ACRCloud recognizer configuration
13
  config = {
 
21
  acr = ACRCloudRecognizer(config)
22
 
23
  def identify_audio(file):
24
+ # Gradio provides a file object, and file.name contains the path
25
+ file_path = file.name # Gradio file object already provides a file path
 
 
 
 
 
26
 
27
  # Get the duration of the audio file in milliseconds
28
  duration_ms = int(acr.get_duration_ms_by_file(file_path))
 
42
  buf = f.read()
43
  buffer_result = acr.recognize_by_filebuffer(buf, 0)
44
 
 
 
 
45
  return {
46
  "Partial Results": results,
47
  "Full Result": full_result,