Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
8 |
# Carregando o modelo Whisper avançado para transcrição de áudio
|
9 |
transcriber = pipeline(
|
10 |
task="automatic-speech-recognition",
|
11 |
-
model="openai/whisper-medium",
|
12 |
device=device,
|
13 |
chunk_length_s=20,
|
14 |
stride_length_s=5,
|
@@ -18,7 +18,7 @@ transcriber = pipeline(
|
|
18 |
# Carregando o tokenizer lento para o classificador
|
19 |
tokenizer = AutoTokenizer.from_pretrained(
|
20 |
"joeddav/xlm-roberta-large-xnli",
|
21 |
-
use_fast=False
|
22 |
)
|
23 |
|
24 |
# Carregando o pipeline de classificação zero-shot com o tokenizer lento
|
@@ -30,34 +30,34 @@ classifier = pipeline(
|
|
30 |
)
|
31 |
|
32 |
def transcribe_and_analyze(audio_file):
|
33 |
-
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
56 |
-
|
57 |
|
58 |
-
|
59 |
|
60 |
-
|
61 |
|
62 |
# Criando a interface Gradio com barra de progresso
|
63 |
interface = gr.Interface(
|
@@ -73,4 +73,4 @@ interface = gr.Interface(
|
|
73 |
)
|
74 |
|
75 |
if __name__ == "__main__":
|
76 |
-
interface.launch()
|
|
|
8 |
# Carregando o modelo Whisper avançado para transcrição de áudio
|
9 |
transcriber = pipeline(
|
10 |
task="automatic-speech-recognition",
|
11 |
+
model="openai/whisper-medium",
|
12 |
device=device,
|
13 |
chunk_length_s=20,
|
14 |
stride_length_s=5,
|
|
|
18 |
# Carregando o tokenizer lento para o classificador
|
19 |
tokenizer = AutoTokenizer.from_pretrained(
|
20 |
"joeddav/xlm-roberta-large-xnli",
|
21 |
+
use_fast=False
|
22 |
)
|
23 |
|
24 |
# Carregando o pipeline de classificação zero-shot com o tokenizer lento
|
|
|
30 |
)
|
31 |
|
32 |
def transcribe_and_analyze(audio_file):
|
33 |
+
progress = gr.Progress(track_tqdm=True)
|
34 |
+
progress(0, desc="Iniciando transcrição...")
|
35 |
|
36 |
+
# Transcrevendo o áudio
|
37 |
+
transcription_result = transcriber(audio_file)
|
38 |
+
transcription = transcription_result["text"]
|
39 |
+
progress(50, desc="Transcrição concluída. Analisando emoções...")
|
40 |
|
41 |
+
# Lista de emoções para a classificação
|
42 |
+
emotions = ["alegria", "tristeza", "raiva", "nojo", "medo", "ansiedade", "vergonha", "tédio", "inveja"]
|
43 |
|
44 |
+
# Realizando a classificação zero-shot
|
45 |
+
classification = classifier(transcription, emotions, multi_label=True)
|
46 |
|
47 |
+
# Formatando os resultados
|
48 |
+
results = []
|
49 |
+
for label, score in zip(classification["labels"], classification["scores"]):
|
50 |
+
results.append(f"{label.capitalize()}: {score:.2f}")
|
51 |
|
52 |
+
# Ordenando os resultados por score decrescente
|
53 |
+
results.sort(key=lambda x: float(x.split(": ")[1]), reverse=True)
|
54 |
|
55 |
+
# Unindo os resultados em uma string
|
56 |
+
emotion_output = "\n".join(results)
|
57 |
|
58 |
+
progress(100, desc="Processamento concluído.")
|
59 |
|
60 |
+
return transcription, emotion_output
|
61 |
|
62 |
# Criando a interface Gradio com barra de progresso
|
63 |
interface = gr.Interface(
|
|
|
73 |
)
|
74 |
|
75 |
if __name__ == "__main__":
|
76 |
+
interface.queue().launch()
|