Spaces:
Runtime error
Runtime error
evertorres-itm
commited on
Commit
·
42a94c6
1
Parent(s):
da2923b
Create app.py
Browse filesPlatzi Project
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
trans = pipeline("automatic-speech-recognition", model ="facebook/wav2vec2-large-xlsr-53-spanish")
|
5 |
+
traductor = pipeline("translation", model = "Helsinki-NLP/opus-mt-es-en")
|
6 |
+
ner = pipeline("ner", model = "d4data/biomedical-ner-all")
|
7 |
+
|
8 |
+
def audio2text(audio):
|
9 |
+
text = trans(audio)["text"]
|
10 |
+
return text
|
11 |
+
|
12 |
+
def text2eng(text):
|
13 |
+
return traductor(text)[0]["translation_text"]
|
14 |
+
|
15 |
+
def eng2ner(text):
|
16 |
+
output = ner(text)
|
17 |
+
return {"text": text, "entities": output}
|
18 |
+
|
19 |
+
demo = gr.Blocks()
|
20 |
+
|
21 |
+
with demo:
|
22 |
+
gr.Markdown("Demo sobre historia clínica en español a entidades en ingles")
|
23 |
+
audio = gr.Audio(sources="microphone", type="filepath")
|
24 |
+
texto = gr.Textbox()
|
25 |
+
b_text = gr.Button("Transcribir")
|
26 |
+
b_text.click(audio2text, inputs=audio, outputs=texto)
|
27 |
+
|
28 |
+
transcripcion = gr.Textbox()
|
29 |
+
b_trans = gr.Button("Traducir historia")
|
30 |
+
b_trans.click(text2eng, inputs=texto, outputs=transcripcion)
|
31 |
+
|
32 |
+
entidades = gr.HighlightedText()
|
33 |
+
b_ner =gr.Button("Search entities")
|
34 |
+
b_ner.click(eng2ner, inputs=transcripcion, outputs=entidades)
|
35 |
+
|
36 |
+
demo.launch()
|