Spaces:
Running
Running
app.py
CHANGED
@@ -1,6 +1,10 @@
|
|
1 |
import requests
|
2 |
import gradio as gr
|
3 |
import os
|
|
|
|
|
|
|
|
|
4 |
|
5 |
API_URL = "https://api-inference.huggingface.co/models/MIT/ast-finetuned-audioset-10-10-0.4593"
|
6 |
headers = {"Authorization": f"Bearer {os.environ.get('HF_TOKEN')}"}
|
@@ -12,12 +16,17 @@ def classify_audio(audio_file):
|
|
12 |
if audio_file is None:
|
13 |
return "Please upload an audio file."
|
14 |
|
15 |
-
with open(audio_file.name, "rb") as f:
|
16 |
-
data = f.read()
|
17 |
-
response = requests.post(API_URL, headers=headers, data=data)
|
18 |
try:
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
except Exception as e:
|
22 |
return f"Error processing audio: {str(e)}"
|
23 |
|
@@ -32,7 +41,5 @@ iface = gr.Interface(
|
|
32 |
)
|
33 |
|
34 |
# Launch the interface
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
1 |
import requests
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
+
import torch
|
5 |
+
|
6 |
+
# Check if CUDA is available and set the device accordingly
|
7 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
8 |
|
9 |
API_URL = "https://api-inference.huggingface.co/models/MIT/ast-finetuned-audioset-10-10-0.4593"
|
10 |
headers = {"Authorization": f"Bearer {os.environ.get('HF_TOKEN')}"}
|
|
|
16 |
if audio_file is None:
|
17 |
return "Please upload an audio file."
|
18 |
|
|
|
|
|
|
|
19 |
try:
|
20 |
+
with open(audio_file.name, "rb") as f:
|
21 |
+
data = f.read()
|
22 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
23 |
+
|
24 |
+
if response.status_code == 200:
|
25 |
+
results = response.json()
|
26 |
+
return results
|
27 |
+
else:
|
28 |
+
return f"Error: API returned status code {response.status_code}"
|
29 |
+
|
30 |
except Exception as e:
|
31 |
return f"Error processing audio: {str(e)}"
|
32 |
|
|
|
41 |
)
|
42 |
|
43 |
# Launch the interface
|
44 |
+
if __name__ == "__main__":
|
45 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|