Spaces:
Runtime error
Runtime error
Armandoliv
commited on
Commit
·
93d7c3b
1
Parent(s):
125f3c8
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
import spacy
|
4 |
+
import os
|
5 |
+
import whisper
|
6 |
+
os.system('pip install https://huggingface.co/Armandoliv/es_pipeline/resolve/main/es_pipeline-any-py3-none-any.whl')
|
7 |
+
os.system('pip install git+https://github.com/openai/whisper.git')
|
8 |
+
|
9 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
10 |
+
|
11 |
+
|
12 |
+
nlp_ner = spacy.load("es_pipeline")
|
13 |
+
|
14 |
+
def main_generator(youtube_id:str):
|
15 |
+
YouTubeID = youtube_id # ¿Qué es la enfermedad de Crohn y cómo detectarla?
|
16 |
+
OutputFile = 'test_audio_youtube_.m4a'
|
17 |
+
|
18 |
+
os.system(f"youtube-dl -o {OutputFile} {YouTubeID} --extract-audio --restrict-filenames -f 'bestaudio[ext=m4a]'")
|
19 |
+
model_whisper = whisper.load_model("small")
|
20 |
+
result = model_whisper.transcribe(OutputFile)
|
21 |
+
text = result['text']
|
22 |
+
output_list = []
|
23 |
+
for ent in doc.ents:
|
24 |
+
result_dict = {
|
25 |
+
'entity': ent.label_,
|
26 |
+
'word': ent.text,
|
27 |
+
'start':ent.start_char,
|
28 |
+
'end': ent.end_char
|
29 |
+
}
|
30 |
+
output_list.append(result_dict)
|
31 |
+
|
32 |
+
return {"text": text, "entities": output_list}
|
33 |
+
inputs = [gr.Textbox(lines=1, placeholder="Link of youtube video here...", label="Input")]
|
34 |
+
outputs = gr.HighlightedText()
|
35 |
+
title="ASR FOR MEDICAL RECORDS"
|
36 |
+
description = "This demo uses AI Models to create an AUDIO ANNOTATION FOR MEDICAL RECORDS"
|
37 |
+
examples = ['xOZM-1p-jAk']
|
38 |
+
|
39 |
+
io = gr.Interface(fn=main_generator, inputs=inputs, outputs=outputs, title=title, description = description, examples = examples,
|
40 |
+
|
41 |
+
css= """.gr-button-primary { background: -webkit-linear-gradient(
|
42 |
+
90deg, #355764 0%, #55a8a1 100% ) !important; background: #355764;
|
43 |
+
background: linear-gradient(
|
44 |
+
90deg, #355764 0%, #55a8a1 100% ) !important;
|
45 |
+
background: -moz-linear-gradient( 90deg, #355764 0%, #55a8a1 100% ) !important;
|
46 |
+
background: -webkit-linear-gradient(
|
47 |
+
90deg, #355764 0%, #55a8a1 100% ) !important;
|
48 |
+
color:white !important}"""
|
49 |
+
)
|
50 |
+
|
51 |
+
io.launch(debug=True)
|