Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,81 +1,52 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
modelo_path = "proxectonos/Nos_ASR-wav2vec2-large-xlsr-53-gl-with-lm"
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
fronted_theme = "Soft"
|
| 7 |
|
| 8 |
-
def cargar(
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
return texto_transcrito
|
| 12 |
|
| 13 |
-
|
| 14 |
-
#send-btn {
|
| 15 |
-
background-color: blue;
|
| 16 |
-
color: white;
|
| 17 |
-
}
|
| 18 |
-
#clear-btn {
|
| 19 |
-
background-color: green;
|
| 20 |
-
color: white;
|
| 21 |
-
}
|
| 22 |
-
#send-btn:hover {
|
| 23 |
-
box-shadow: 3px 3px 5px #0056b3;
|
| 24 |
-
}
|
| 25 |
-
#clear-btn:hover {
|
| 26 |
-
box-shadow: 3px 3px 5px #1e7e34;
|
| 27 |
-
}
|
| 28 |
|
| 29 |
-
""
|
|
|
|
| 30 |
|
| 31 |
-
with gr.Blocks(fronted_theme
|
| 32 |
with gr.Row():
|
| 33 |
with gr.Column():
|
| 34 |
gr.Markdown(
|
| 35 |
-
"""
|
| 36 |
-
## <h1 style="text-align:center">🗣️📄 ASR Demo Proxecto Nós </h1>
|
| 37 |
-
"""
|
| 38 |
)
|
| 39 |
gr.Markdown(
|
| 40 |
-
"""
|
| 41 |
-
## <img src="https://huggingface.co/spaces/proxectonos/README/resolve/main/title-card.png" width="100%" style="border-radius: 0.75rem;">
|
| 42 |
-
"""
|
| 43 |
)
|
| 44 |
with gr.Column():
|
| 45 |
-
with gr.Row():
|
| 46 |
gr.Markdown(
|
| 47 |
-
"""
|
| 48 |
-
<br/>
|
| 49 |
-
<br/>
|
| 50 |
-
<br/>
|
| 51 |
-
<br/>
|
| 52 |
-
|
| 53 |
-
💻 Este space mostra o modelo ASR desenvolvido polo **[Proxecto Nós](https://huggingface.co/proxectonos)**.
|
| 54 |
-
<br/>
|
| 55 |
-
"""
|
| 56 |
)
|
| 57 |
-
with gr.Row():
|
| 58 |
input_audio = gr.Audio(label="Entrada", type="filepath")
|
| 59 |
-
with gr.Row():
|
| 60 |
output_text = gr.Textbox(label="Saída", type="text")
|
| 61 |
with gr.Row():
|
| 62 |
asr_button = gr.Button("Xerar", elem_id="send-btn", visible=True)
|
| 63 |
clear_button = gr.ClearButton([input_audio, output_text], value="Limpar", elem_id="clear-btn", visible=True)
|
| 64 |
|
| 65 |
-
|
| 66 |
asr_button.click(
|
| 67 |
cargar,
|
| 68 |
-
inputs=[
|
| 69 |
-
input_audio,
|
| 70 |
-
],
|
| 71 |
-
outputs=[output_text],
|
| 72 |
-
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
examples = gr.Examples(
|
| 76 |
-
["Celtia1.wav"],
|
| 77 |
inputs=[input_audio],
|
| 78 |
-
|
| 79 |
)
|
| 80 |
|
| 81 |
-
demo.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
modelo_path = "proxectonos/Nos_ASR-wav2vec2-large-xlsr-53-gl-with-lm"
|
| 6 |
+
|
| 7 |
+
asr_pipeline = pipeline(
|
| 8 |
+
"automatic-speech-recognition",
|
| 9 |
+
model=modelo_path,
|
| 10 |
+
device=0 if torch.cuda.is_available() else -1
|
| 11 |
+
)
|
| 12 |
|
| 13 |
fronted_theme = "Soft"
|
| 14 |
|
| 15 |
+
def cargar(audio_filepath):
|
| 16 |
+
if audio_filepath is None:
|
| 17 |
+
return "Por favor, carga un ficheiro de audio."
|
|
|
|
| 18 |
|
| 19 |
+
outtext = asr_pipeline(audio_filepath)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
texto_transcrito = outtext["text"]
|
| 22 |
+
return texto_transcrito
|
| 23 |
|
| 24 |
+
with gr.Blocks(fronted_theme) as demo:
|
| 25 |
with gr.Row():
|
| 26 |
with gr.Column():
|
| 27 |
gr.Markdown(
|
| 28 |
+
""" ## <h1 style="text-align:center">🗣️ ASR Demo Proxecto Nós </h1> """
|
|
|
|
|
|
|
| 29 |
)
|
| 30 |
gr.Markdown(
|
| 31 |
+
""" ## <img src="https://huggingface.co/spaces/proxectonos/README/resolve/main/title-card.png" width="100%" style="border-radius: 0.75rem;"> """
|
|
|
|
|
|
|
| 32 |
)
|
| 33 |
with gr.Column():
|
| 34 |
+
with gr.Row():
|
| 35 |
gr.Markdown(
|
| 36 |
+
""" <br/> <br/> <br/> <br/> Este space mostra o modelo ASR desenvolvido polo **[Proxecto Nós](https://huggingface.co/proxectonos)**. <br/> """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
)
|
| 38 |
+
with gr.Row():
|
| 39 |
input_audio = gr.Audio(label="Entrada", type="filepath")
|
| 40 |
+
with gr.Row():
|
| 41 |
output_text = gr.Textbox(label="Saída", type="text")
|
| 42 |
with gr.Row():
|
| 43 |
asr_button = gr.Button("Xerar", elem_id="send-btn", visible=True)
|
| 44 |
clear_button = gr.ClearButton([input_audio, output_text], value="Limpar", elem_id="clear-btn", visible=True)
|
| 45 |
|
|
|
|
| 46 |
asr_button.click(
|
| 47 |
cargar,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
inputs=[input_audio],
|
| 49 |
+
outputs=[output_text],
|
| 50 |
)
|
| 51 |
|
| 52 |
+
demo.launch()
|