Spaces:
Sleeping
Sleeping
Rivalcoder
commited on
Commit
·
ba773e9
1
Parent(s):
4b25dd0
Add Files -Update New
Browse files- alm_pipeline.py +16 -10
- reasoning.py +2 -1
alm_pipeline.py
CHANGED
|
@@ -4,14 +4,18 @@ import warnings
|
|
| 4 |
import whisper
|
| 5 |
import librosa
|
| 6 |
import numpy as np
|
|
|
|
| 7 |
import tensorflow_hub as hub
|
|
|
|
| 8 |
|
| 9 |
-
# Reduce TensorFlow log noise and avoid attempting GPU / oneDNN on CPU-only envs
|
|
|
|
|
|
|
| 10 |
os.environ.setdefault("TF_CPP_MIN_LOG_LEVEL", "2") # hide INFO/WARNING logs
|
| 11 |
os.environ.setdefault("TF_ENABLE_ONEDNN_OPTS", "0") # disable oneDNN custom ops
|
| 12 |
os.environ.setdefault("CUDA_VISIBLE_DEVICES", "-1") # don't try to use CUDA GPUs
|
| 13 |
|
| 14 |
-
# Suppress specific library warnings that are expected in this setup
|
| 15 |
warnings.filterwarnings(
|
| 16 |
"ignore",
|
| 17 |
category=UserWarning,
|
|
@@ -28,7 +32,14 @@ asr_model = whisper.load_model("small")
|
|
| 28 |
|
| 29 |
# Load YAMNet for sound classification
|
| 30 |
yamnet = hub.load("https://tfhub.dev/google/yamnet/1")
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Simple Emotion Estimator (from YAMNet embedding)
|
| 34 |
def estimate_emotion(activation):
|
|
@@ -53,13 +64,8 @@ def detect_sound(audio):
|
|
| 53 |
scores, embeddings, _ = yamnet(waveform)
|
| 54 |
mean_scores = np.mean(scores.numpy(), axis=0)
|
| 55 |
top_idx = int(np.argmax(mean_scores))
|
| 56 |
-
#
|
| 57 |
-
|
| 58 |
-
label = class_map[top_idx]
|
| 59 |
-
if isinstance(label, bytes):
|
| 60 |
-
label = label.decode("utf-8")
|
| 61 |
-
else:
|
| 62 |
-
label = str(label)
|
| 63 |
return label, float(mean_scores.max())
|
| 64 |
|
| 65 |
|
|
|
|
| 4 |
import whisper
|
| 5 |
import librosa
|
| 6 |
import numpy as np
|
| 7 |
+
import tensorflow as tf
|
| 8 |
import tensorflow_hub as hub
|
| 9 |
+
import csv
|
| 10 |
|
| 11 |
+
# Reduce TensorFlow log noise and avoid attempting GPU / oneDNN on CPU-only envs.
|
| 12 |
+
# NOTE: These env vars must be set before TensorFlow fully initializes; setting them
|
| 13 |
+
# here greatly reduces, but may not completely remove, startup logs on some platforms.
|
| 14 |
os.environ.setdefault("TF_CPP_MIN_LOG_LEVEL", "2") # hide INFO/WARNING logs
|
| 15 |
os.environ.setdefault("TF_ENABLE_ONEDNN_OPTS", "0") # disable oneDNN custom ops
|
| 16 |
os.environ.setdefault("CUDA_VISIBLE_DEVICES", "-1") # don't try to use CUDA GPUs
|
| 17 |
|
| 18 |
+
# Suppress specific library warnings that are expected in this setup.
|
| 19 |
warnings.filterwarnings(
|
| 20 |
"ignore",
|
| 21 |
category=UserWarning,
|
|
|
|
| 32 |
|
| 33 |
# Load YAMNet for sound classification
|
| 34 |
yamnet = hub.load("https://tfhub.dev/google/yamnet/1")
|
| 35 |
+
class_map_path = yamnet.class_map_path().numpy()
|
| 36 |
+
if isinstance(class_map_path, bytes):
|
| 37 |
+
class_map_path = class_map_path.decode("utf-8")
|
| 38 |
+
|
| 39 |
+
# Parse YAMNet class map CSV to get human-readable labels
|
| 40 |
+
with tf.io.gfile.GFile(class_map_path) as f:
|
| 41 |
+
reader = csv.DictReader(f)
|
| 42 |
+
yamnet_labels = [row["display_name"] for row in reader]
|
| 43 |
|
| 44 |
# Simple Emotion Estimator (from YAMNet embedding)
|
| 45 |
def estimate_emotion(activation):
|
|
|
|
| 64 |
scores, embeddings, _ = yamnet(waveform)
|
| 65 |
mean_scores = np.mean(scores.numpy(), axis=0)
|
| 66 |
top_idx = int(np.argmax(mean_scores))
|
| 67 |
+
# Look up human-readable class label from YAMNet's CSV class map
|
| 68 |
+
label = yamnet_labels[top_idx] if 0 <= top_idx < len(yamnet_labels) else "Unknown"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
return label, float(mean_scores.max())
|
| 70 |
|
| 71 |
|
reasoning.py
CHANGED
|
@@ -14,5 +14,6 @@ Speakers: {summary['speakers']}
|
|
| 14 |
Question: {question}
|
| 15 |
Provide a detailed reasoning-based answer using the audio cues.
|
| 16 |
"""
|
| 17 |
-
|
|
|
|
| 18 |
return result
|
|
|
|
| 14 |
Question: {question}
|
| 15 |
Provide a detailed reasoning-based answer using the audio cues.
|
| 16 |
"""
|
| 17 |
+
# Use only max_new_tokens to avoid Hugging Face warning about max_length+max_new_tokens.
|
| 18 |
+
result = reasoner(prompt, max_new_tokens=256)[0]["generated_text"]
|
| 19 |
return result
|