Spaces:
Runtime error
Runtime error
File size: 2,160 Bytes
93d7c3b fb94c0b 93d7c3b 0e84678 a6aebb9 93d7c3b 11d953b 6c16ee3 11d953b a70cc2a 93d7c3b a6aebb9 93d7c3b a6aebb9 93d7c3b 4a20b9f 8ec2336 11d953b 93d7c3b bd53cf1 93d7c3b fb94c0b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
import torch
import spacy
import os
import whisper
os.system('pip install https://huggingface.co/Armandoliv/es_pipeline/resolve/main/es_pipeline-any-py3-none-any.whl')
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model_whisper = whisper.load_model("small")
nlp_ner = spacy.load("es_pipeline")
def main_generator(youtube_id:str):
YouTubeID = youtube_id.split("https://www.youtube.com/watch?v=") #
if len(YouTubeID)>1:
YouTubeID = YouTubeID[1]
else:
YouTubeID ='XfyGv-xwjlI'
OutputFile = f'test_audio_youtube_{YouTubeID}.m4a'
os.system(f"youtube-dl -o {OutputFile} {YouTubeID} --extract-audio --restrict-filenames -f 'bestaudio[ext=m4a]'")
result = model_whisper.transcribe(OutputFile)
text = result['text']
doc = nlp_ner(text)
output_list = []
for ent in doc.ents:
result_dict = {
'entity': ent.label_,
'word': ent.text,
'start':ent.start_char,
'end': ent.end_char
}
output_list.append(result_dict)
return {"text": text, "entities": output_list}
inputs = [gr.Textbox(lines=1, placeholder="Link of youtube video here...", label="Input")]
outputs = gr.HighlightedText()
title="ASR FOR SPANISH MEDICAL RECORDS"
description = "This demo uses AI Models to create an AUDIO ANNOTATION FOR MEDICAL RECORDS "
examples = ['https://www.youtube.com/watch?v=xOZM-1p-jAk']
io = gr.Interface(fn=main_generator, inputs=inputs, outputs=outputs, title=title, description = description, examples = examples,
css= """.gr-button-primary { background: -webkit-linear-gradient(
70deg, #355764 0%, #55a8a1 100% ) !important; background: #355764;
background: linear-gradient(
90deg, #355764 0%, #55a8a1 100% ) !important;
background: -moz-linear-gradient( 90deg, #355764 0%, #55a8a1 100% ) !important;
background: -webkit-linear-gradient(
90deg, #355764 0%, #55a8a1 100% ) !important;
color:white !important}"""
)
io.launch() |