avilaroman commited on
Commit
448fefc
1 Parent(s): 91f208f

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +12 -1
  2. app.py +97 -0
  3. packages.txt +1 -0
  4. requirements.txt +3 -0
README.md CHANGED
@@ -1,3 +1,14 @@
1
  ---
2
- license: cc-by-nc-nd-4.0
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
1
  ---
2
+ title: escucharadio
3
+ emoji: 🤫
4
+ colorFrom: indigo
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 3.9.1
8
+ app_file: app.py
9
+ pinned: false
10
+ tags:
11
+ - whisper-event
12
  ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ import gradio as gr
4
+ import pytube as pt
5
+ from transformers import pipeline
6
+ from huggingface_hub import model_info
7
+
8
+ MODEL_NAME = "openai/whisper-small" #Ésto es la base de con lo que trabaja el script entonces hay que cargarlo en la linea 8.
9
+ lang = "es"
10
+
11
+ device = 0 if torch.cuda.is_available() else "cpu"
12
+ pipe = pipeline(
13
+ task="automatic-speech-recognition",
14
+ model=MODEL_NAME,
15
+ chunk_length_s=30,
16
+ device=device,
17
+ )
18
+
19
+ pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
20
+
21
+ def transcribe(microphone, file_upload):
22
+ warn_output = ""
23
+ if (microphone is not None) and (file_upload is not None):
24
+ warn_output = (
25
+ "Consejo: Subiste un Archivo de Audio y usado el micrófono. "
26
+ "el Archivo Grabado del Microfono Local será enviado a Analizar. OK!\n"
27
+ )
28
+
29
+ elif (microphone is None) and (file_upload is None):
30
+ return "Advertencia: Tu tienes los 2 usa el Micrófono o un archivo subido desde tu PC."
31
+
32
+ file = microphone if microphone is not None else file_upload
33
+
34
+ text = pipe(file)["text"]
35
+
36
+ return warn_output + text
37
+
38
+
39
+ def _return_yt_html_embed(yt_url):
40
+ video_id = yt_url.split("?v=")[-1]
41
+ HTML_str = (
42
+ f'<center> <iframe width="500" height="320" src="https://www.youtube.com/embed/{video_id}"> </iframe>'
43
+ " </center>"
44
+ )
45
+ return HTML_str
46
+
47
+
48
+ def yt_transcribe(yt_url):
49
+ yt = pt.YouTube(yt_url)
50
+ html_embed_str = _return_yt_html_embed(yt_url)
51
+ stream = yt.streams.filter(only_audio=True)[0]
52
+ stream.download(filename="audio.mp3")
53
+
54
+ text = pipe("audio.mp3")["text"]
55
+
56
+ return html_embed_str, text
57
+
58
+
59
+ demo = gr.Blocks()
60
+
61
+ mf_transcribe = gr.Interface(
62
+ fn=transcribe,
63
+ inputs=[
64
+ gr.inputs.Audio(source="microphone", type="filepath", optional=True),
65
+ gr.inputs.Audio(source="upload", type="filepath", optional=True),
66
+ ],
67
+ outputs="text",
68
+ layout="horizontal",
69
+ theme="huggingface",
70
+ title="TranscribeRadio",
71
+ description=(
72
+ "Transcribe Largas capturas de audio de Radio 160.310 Mgh por micrófono o grabaciones desde archivos a 1 click y gratis! Ésta version está utilizando por defecto fine-tuned para el mejor aprovechamiento del contexto."
73
+ f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files"
74
+ " of arbitrary length."
75
+ ),
76
+ allow_flagging="never",
77
+ )
78
+
79
+ yt_transcribe = gr.Interface(
80
+ fn=yt_transcribe,
81
+ inputs=[gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL")],
82
+ outputs=["html", "text"],
83
+ layout="horizontal",
84
+ theme="huggingface",
85
+ title="Whisper Demo: Transcribe YouTube",
86
+ description=(
87
+ "Transcribe Largas capturas de audio de Radio 160.310 Mgh por micrófono o grabaciones desde archivos a 1 click y gratis! Ésta version está utilizando por defecto fine-tuned para el mejor aprovechamiento del contexto."
88
+ f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe audio files of"
89
+ " arbitrary length."
90
+ ),
91
+ allow_flagging="never",
92
+ )
93
+
94
+ with demo:
95
+ gr.TabbedInterface([mf_transcribe, yt_transcribe], ["Transcribe Audio", "Transcribe YouTube"])
96
+
97
+ demo.launch(enable_queue=True)
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ git+https://github.com/huggingface/transformers
2
+ torch
3
+ pytube