MReyess commited on
Commit
1410120
路
verified 路
1 Parent(s): bc07da1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -7
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import gradio as gr
2
  import whisper
 
 
3
  from transformers import pipeline
4
 
5
  # 1. Modelo ASR
@@ -18,10 +20,10 @@ sentiment_model = pipeline(
18
  # model="audeering/wav2vec2-large-robust-6-ft-age-gender"
19
  #)
20
 
21
- gender_model = pipeline(
22
- "audio-classification",
23
- model="JaesungHuh/voice-gender-classifier"
24
- )
25
 
26
  def transcribe_audio(audio_path):
27
  result = asr_model.transcribe(audio_path, language="es")
@@ -54,7 +56,7 @@ def classify_sentiment(text):
54
  label = label_map.get(best["label"], best["label"])
55
  score = round(best["score"] * 100, 2)
56
 
57
- return f"{label} ({score}% de confianza)"'''
58
 
59
 
60
  def classify_gender(audio_path):
@@ -73,7 +75,34 @@ def classify_gender(audio_path):
73
  label = label_map.get(best["label"], best["label"])
74
  score = round(best["score"] * 100, 2)
75
 
76
- return f"{label} ({score}% de confianza)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  def transcribe_and_classify(audio_path):
79
  if audio_path is None:
@@ -98,9 +127,11 @@ def transcribe_and_classify(audio_path):
98
 
99
  # G茅nero vocal estimado
100
  try:
101
- gender_result = classify_gender(audio_path)
 
102
  except Exception as e:
103
  gender_result = f"Error en g茅nero vocal: {str(e)}"
 
104
 
105
  return text, sentiment_result, gender_result
106
 
 
1
  import gradio as gr
2
  import whisper
3
+ import librosa
4
+ import numpy as np
5
  from transformers import pipeline
6
 
7
  # 1. Modelo ASR
 
20
  # model="audeering/wav2vec2-large-robust-6-ft-age-gender"
21
  #)
22
 
23
+ #gender_model = pipeline(
24
+ # "audio-classification",
25
+ # model="JaesungHuh/voice-gender-classifier"
26
+ #)
27
 
28
  def transcribe_audio(audio_path):
29
  result = asr_model.transcribe(audio_path, language="es")
 
56
  label = label_map.get(best["label"], best["label"])
57
  score = round(best["score"] * 100, 2)
58
 
59
+ return f"{label} ({score}% de confianza)"
60
 
61
 
62
  def classify_gender(audio_path):
 
75
  label = label_map.get(best["label"], best["label"])
76
  score = round(best["score"] * 100, 2)
77
 
78
+ return f"{label} ({score}% de confianza)" '''
79
+
80
+ def estimate_voice_f0(audio_path):
81
+
82
+ y, sr = librosa.load(audio_path, sr=16000)
83
+
84
+ f0, voiced_flag, voiced_probs = librosa.pyin(
85
+ y,
86
+ fmin=50,
87
+ fmax=400
88
+ )
89
+
90
+ f0_valid = f0[~np.isnan(f0)]
91
+
92
+ if len(f0_valid) == 0:
93
+ return "No fue posible estimar F0."
94
+
95
+ mean_f0 = np.mean(f0_valid)
96
+
97
+ if mean_f0 < 165:
98
+ gender = "Hombre"
99
+ else:
100
+ gender = "Mujer"
101
+
102
+ return (
103
+ f"F0 promedio: {mean_f0:.1f} Hz\n"
104
+ f"Estimaci贸n simple: {gender}"
105
+ )
106
 
107
  def transcribe_and_classify(audio_path):
108
  if audio_path is None:
 
127
 
128
  # G茅nero vocal estimado
129
  try:
130
+ #gender_result = classify_gender(audio_path)
131
+ gender_result = estimate_voice_f0(audio_path)
132
  except Exception as e:
133
  gender_result = f"Error en g茅nero vocal: {str(e)}"
134
+
135
 
136
  return text, sentiment_result, gender_result
137