Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,39 @@
|
|
1 |
-
from datasets import load_dataset, concatenate_datasets
|
2 |
-
import pandas as pd
|
3 |
import gradio as gr
|
|
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
notes_dataset = load_dataset('csv', data_files={'train': notes_csv_path})
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
display_df = df[display_columns].head() # Mostra as primeiras linhas do dataset combinado
|
24 |
-
|
25 |
-
return display_df
|
26 |
|
27 |
# Configurar a interface Gradio
|
28 |
iface = gr.Interface(
|
29 |
-
fn=
|
30 |
-
inputs=
|
31 |
-
outputs="
|
32 |
-
title="
|
33 |
-
description="
|
34 |
)
|
35 |
|
36 |
iface.launch(share=True) # share=True para gerar um link público
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import librosa
|
3 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Tokenizer
|
4 |
+
import torch
|
5 |
|
6 |
+
# Carregar o modelo e o tokenizer pré-treinados para reconhecimento de fala
|
7 |
+
tokenizer = Wav2Vec2Tokenizer.from_pretrained("facebook/wav2vec2-large-960h")
|
8 |
+
model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-large-960h")
|
|
|
9 |
|
10 |
+
def transcribe_audio(audio_file):
|
11 |
+
# Carregar o arquivo de áudio
|
12 |
+
y, sr = librosa.load(audio_file, sr=16000) # Wav2Vec2 espera áudio com taxa de amostragem de 16kHz
|
13 |
+
input_values = tokenizer(y, return_tensors="pt", padding="longest").input_values
|
14 |
+
logits = model(input_values).logits
|
15 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
16 |
+
transcription = tokenizer.batch_decode(predicted_ids)[0]
|
17 |
+
return transcription
|
18 |
|
19 |
+
def identify_song_and_lyrics(audio_file):
|
20 |
+
transcription = transcribe_audio(audio_file)
|
21 |
+
# Placeholder para lógica de identificação da música e obtenção das letras e cifras
|
22 |
+
song_info = {
|
23 |
+
"title": "Título da Música (Placeholder)",
|
24 |
+
"artist": "Artista (Placeholder)",
|
25 |
+
"lyrics": transcription, # Usar a transcrição como placeholder
|
26 |
+
"chords": "Cifra (Placeholder)"
|
27 |
+
}
|
28 |
+
return song_info
|
|
|
|
|
|
|
29 |
|
30 |
# Configurar a interface Gradio
|
31 |
iface = gr.Interface(
|
32 |
+
fn=identify_song_and_lyrics,
|
33 |
+
inputs=gr.inputs.Audio(source="upload", type="file"),
|
34 |
+
outputs="json",
|
35 |
+
title="Identificação de Música e Exibição de Letras e Cifras",
|
36 |
+
description="Carregue um arquivo de áudio para identificar a música e visualizar a cifra e a letra."
|
37 |
)
|
38 |
|
39 |
iface.launch(share=True) # share=True para gerar um link público
|