Spaces:
Runtime error
Runtime error
Sebastian Tinoco
commited on
Commit
•
a394acb
1
Parent(s):
2bde6db
first commit
Browse files- app.py +64 -0
- requirements.txt +74 -0
- utils.py +15 -0
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import torch
|
3 |
+
import gradio as gr
|
4 |
+
import os
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
from huggingface_hub import login
|
7 |
+
from utils import parse_args
|
8 |
+
|
9 |
+
|
10 |
+
args = parse_args()
|
11 |
+
|
12 |
+
model = args['model']
|
13 |
+
model_name = "clinical-assistance/" + model
|
14 |
+
|
15 |
+
# Load secrets
|
16 |
+
load_dotenv()
|
17 |
+
token = os.getenv("TOKEN")
|
18 |
+
assert token is not None, 'Hugging Face token has not been specified. Please specify your token in a .env file.'
|
19 |
+
|
20 |
+
# Login to Hugging Face
|
21 |
+
login(token=token)
|
22 |
+
|
23 |
+
# Init model
|
24 |
+
device = 'cuda:0' if torch.cuda.is_available() else 'cpu'
|
25 |
+
generate_kwargs = {"language":"<|es|>", "task": "transcribe"}
|
26 |
+
pipe = pipeline(model=model_name, generate_kwargs=generate_kwargs, device = device)
|
27 |
+
|
28 |
+
def model_transcribe(audio):
|
29 |
+
'''
|
30 |
+
Transcribes audio to text using the Whisper model.
|
31 |
+
'''
|
32 |
+
text = pipe(audio)["text"]
|
33 |
+
return text
|
34 |
+
|
35 |
+
# Define the Gradio app with the correct syntax for loading the function and handling inputs/outputs
|
36 |
+
with gr.Blocks(theme=gr.themes.Base()) as demo:
|
37 |
+
|
38 |
+
with gr.Row():
|
39 |
+
gr.Markdown(
|
40 |
+
"""
|
41 |
+
# Transcripción Automática de Consultas Médicas 👨🏻⚕️🚀
|
42 |
+
Bienvenido a la herramienta de transcripción de consultas médicas! Esta herramienta está diseñada para transcribir grabaciones de consultas médicas usando `Whisper`.
|
43 |
+
## Cómo usar esta herramienta?
|
44 |
+
Usar esta herramienta es fácil! Sólo debes seguir los siguientes pasos:
|
45 |
+
1. Sube la grabación de una consulta médica. Opcionalmente puedes grabar audio y subir la grabación.
|
46 |
+
2. Realizar click en "Transcribir" para comenzar el proceso de transcripción.
|
47 |
+
3. Visualizar el audio transcrito en el panel de la derecha.
|
48 |
+
|
49 |
+
Eso es todo! Estás listo para transcribir grabaciones de consultas médicas de manera automática. Que lo disfrutes!
|
50 |
+
"""
|
51 |
+
)
|
52 |
+
|
53 |
+
with gr.Row():
|
54 |
+
audio_input = gr.Audio(sources=["upload", "microphone"], type="filepath", label="Audio de Entrada")
|
55 |
+
text_output = gr.Textbox(label="Texto de Salida")
|
56 |
+
|
57 |
+
with gr.Row():
|
58 |
+
button = gr.Button("Transcribir")
|
59 |
+
|
60 |
+
# Correct method to link function with inputs and outputs
|
61 |
+
button.click(fn=model_transcribe, inputs=audio_input, outputs=text_output)
|
62 |
+
|
63 |
+
# Use demo.launch() to launch the interface with optional debug mode
|
64 |
+
demo.launch(debug=True, share = True)
|
requirements.txt
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
altair==5.3.0
|
3 |
+
annotated-types==0.6.0
|
4 |
+
anyio==4.3.0
|
5 |
+
attrs==23.2.0
|
6 |
+
certifi==2024.2.2
|
7 |
+
charset-normalizer==3.3.2
|
8 |
+
click==8.1.7
|
9 |
+
contourpy==1.2.1
|
10 |
+
cycler==0.12.1
|
11 |
+
exceptiongroup==1.2.1
|
12 |
+
fastapi==0.110.2
|
13 |
+
ffmpy==0.3.2
|
14 |
+
filelock==3.13.4
|
15 |
+
fonttools==4.51.0
|
16 |
+
fsspec==2024.3.1
|
17 |
+
gradio==4.27.0
|
18 |
+
gradio_client==0.15.1
|
19 |
+
h11==0.14.0
|
20 |
+
httpcore==1.0.5
|
21 |
+
httpx==0.27.0
|
22 |
+
huggingface-hub==0.22.2
|
23 |
+
idna==3.7
|
24 |
+
importlib_resources==6.4.0
|
25 |
+
Jinja2==3.1.3
|
26 |
+
jsonschema==4.21.1
|
27 |
+
jsonschema-specifications==2023.12.1
|
28 |
+
kiwisolver==1.4.5
|
29 |
+
markdown-it-py==3.0.0
|
30 |
+
MarkupSafe==2.1.5
|
31 |
+
matplotlib==3.8.4
|
32 |
+
mdurl==0.1.2
|
33 |
+
mpmath==1.3.0
|
34 |
+
networkx==3.3
|
35 |
+
numpy==1.26.4
|
36 |
+
orjson==3.10.1
|
37 |
+
packaging==24.0
|
38 |
+
pandas==2.2.2
|
39 |
+
pillow==10.3.0
|
40 |
+
pydantic==2.7.0
|
41 |
+
pydantic_core==2.18.1
|
42 |
+
pydub==0.25.1
|
43 |
+
Pygments==2.17.2
|
44 |
+
pyparsing==3.1.2
|
45 |
+
python-dateutil==2.9.0.post0
|
46 |
+
python-dotenv==1.0.1
|
47 |
+
python-multipart==0.0.9
|
48 |
+
pytz==2024.1
|
49 |
+
PyYAML==6.0.1
|
50 |
+
referencing==0.34.0
|
51 |
+
regex==2024.4.16
|
52 |
+
requests==2.31.0
|
53 |
+
rich==13.7.1
|
54 |
+
rpds-py==0.18.0
|
55 |
+
ruff==0.4.1
|
56 |
+
safetensors==0.4.3
|
57 |
+
semantic-version==2.10.0
|
58 |
+
shellingham==1.5.4
|
59 |
+
six==1.16.0
|
60 |
+
sniffio==1.3.1
|
61 |
+
starlette==0.37.2
|
62 |
+
sympy==1.12
|
63 |
+
tokenizers==0.19.1
|
64 |
+
tomlkit==0.12.0
|
65 |
+
toolz==0.12.1
|
66 |
+
torch==2.2.2
|
67 |
+
tqdm==4.66.2
|
68 |
+
transformers==4.40.0
|
69 |
+
typer==0.12.3
|
70 |
+
typing_extensions==4.11.0
|
71 |
+
tzdata==2024.1
|
72 |
+
urllib3==2.2.1
|
73 |
+
uvicorn==0.29.0
|
74 |
+
websockets==11.0.3
|
utils.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
from distutils.util import strtobool
|
3 |
+
|
4 |
+
def parse_args():
|
5 |
+
|
6 |
+
parser = argparse.ArgumentParser()
|
7 |
+
|
8 |
+
# env arguments
|
9 |
+
parser.add_argument('--model', type = str, default = 'whisper_medium_baseline_1', help = 'whisper model for inference')
|
10 |
+
|
11 |
+
# consolidate args
|
12 |
+
args = parser.parse_args()
|
13 |
+
args = vars(args)
|
14 |
+
|
15 |
+
return args
|