Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# Initialize the audio classification pipeline with the MIT model
|
| 5 |
pipe = pipeline("audio-classification", model="MIT/ast-finetuned-audioset-10-10-0.4593")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# --- Performance Improvement ---
|
| 6 |
+
# 1. Determine the number of available CPU cores.
|
| 7 |
+
num_cpu_cores = os.cpu_count()
|
| 8 |
+
|
| 9 |
+
# 2. Configure PyTorch to use all available CPU cores for its operations.
|
| 10 |
+
# This is crucial for speeding up model inference on a CPU.
|
| 11 |
+
if num_cpu_cores is not None:
|
| 12 |
+
torch.set_num_threads(num_cpu_cores)
|
| 13 |
+
print(f"✅ PyTorch is configured to use {num_cpu_cores} CPU cores.")
|
| 14 |
+
else:
|
| 15 |
+
print("Could not determine the number of CPU cores. Using default settings.")
|
| 16 |
|
| 17 |
# Initialize the audio classification pipeline with the MIT model
|
| 18 |
pipe = pipeline("audio-classification", model="MIT/ast-finetuned-audioset-10-10-0.4593")
|