Spaces:
Sleeping
Sleeping
Commit
·
3621473
1
Parent(s):
e8b6f1a
up
Browse files- run_demo.py +32 -7
run_demo.py
CHANGED
@@ -1,14 +1,29 @@
|
|
1 |
-
import
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
import pytube as pt
|
5 |
-
|
6 |
from huggingface_hub import model_info
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
MODEL_NAME = "bofenghuang/whisper-
|
9 |
CHUNK_LENGTH_S = 30
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
device = 0 if torch.cuda.is_available() else "cpu"
|
|
|
|
|
12 |
pipe = pipeline(
|
13 |
task="automatic-speech-recognition",
|
14 |
model=MODEL_NAME,
|
@@ -33,6 +48,8 @@ def transcribe(microphone, file_upload):
|
|
33 |
|
34 |
text = pipe(file)["text"]
|
35 |
|
|
|
|
|
36 |
return warn_output + text
|
37 |
|
38 |
|
@@ -53,6 +70,8 @@ def yt_transcribe(yt_url):
|
|
53 |
|
54 |
text = pipe("audio.mp3")["text"]
|
55 |
|
|
|
|
|
56 |
return html_embed_str, text
|
57 |
|
58 |
|
@@ -61,10 +80,11 @@ demo = gr.Blocks()
|
|
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="Whisper French Demo 🇫🇷 : Transcribe Audio",
|
@@ -79,7 +99,11 @@ mf_transcribe = gr.Interface(
|
|
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 French Demo 🇫🇷 : Transcribe YouTube",
|
@@ -94,4 +118,5 @@ yt_transcribe = gr.Interface(
|
|
94 |
with demo:
|
95 |
gr.TabbedInterface([mf_transcribe, yt_transcribe], ["Transcribe Audio", "Transcribe YouTube"])
|
96 |
|
|
|
97 |
demo.launch(enable_queue=True)
|
|
|
1 |
+
import logging
|
2 |
+
import warnings
|
3 |
|
4 |
import gradio as gr
|
5 |
import pytube as pt
|
6 |
+
import torch
|
7 |
from huggingface_hub import model_info
|
8 |
+
from transformers import pipeline
|
9 |
+
from transformers.utils.logging import disable_progress_bar
|
10 |
+
|
11 |
+
warnings.filterwarnings("ignore")
|
12 |
+
disable_progress_bar()
|
13 |
|
14 |
+
MODEL_NAME = "bofenghuang/whisper-large-v2-cv11-french"
|
15 |
CHUNK_LENGTH_S = 30
|
16 |
|
17 |
+
logging.basicConfig(
|
18 |
+
format="%(asctime)s [%(levelname)s] [%(name)s] %(message)s",
|
19 |
+
datefmt="%Y-%m-%dT%H:%M:%SZ",
|
20 |
+
)
|
21 |
+
logger = logging.getLogger(__name__)
|
22 |
+
logger.setLevel(logging.DEBUG)
|
23 |
+
|
24 |
device = 0 if torch.cuda.is_available() else "cpu"
|
25 |
+
logger.info(f"Model will be loaded on device `{device}`")
|
26 |
+
|
27 |
pipe = pipeline(
|
28 |
task="automatic-speech-recognition",
|
29 |
model=MODEL_NAME,
|
|
|
48 |
|
49 |
text = pipe(file)["text"]
|
50 |
|
51 |
+
logger.info(f"Transcription: {text}")
|
52 |
+
|
53 |
return warn_output + text
|
54 |
|
55 |
|
|
|
70 |
|
71 |
text = pipe("audio.mp3")["text"]
|
72 |
|
73 |
+
logger.info(f'Transcription of "{yt_url}": {text}')
|
74 |
+
|
75 |
return html_embed_str, text
|
76 |
|
77 |
|
|
|
80 |
mf_transcribe = gr.Interface(
|
81 |
fn=transcribe,
|
82 |
inputs=[
|
83 |
+
gr.inputs.Audio(source="microphone", type="filepath", optional=True, label="Record"),
|
84 |
+
gr.inputs.Audio(source="upload", type="filepath", optional=True, label="Upload File"),
|
85 |
],
|
86 |
+
# outputs="text",
|
87 |
+
outputs=gr.outputs.Textbox(label="Transcription"),
|
88 |
layout="horizontal",
|
89 |
theme="huggingface",
|
90 |
title="Whisper French Demo 🇫🇷 : Transcribe Audio",
|
|
|
99 |
yt_transcribe = gr.Interface(
|
100 |
fn=yt_transcribe,
|
101 |
inputs=[gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL")],
|
102 |
+
# outputs=["html", "text"],
|
103 |
+
outputs=[
|
104 |
+
gr.outputs.HTML(label="YouTube Page"),
|
105 |
+
gr.outputs.Textbox(label="Transcription"),
|
106 |
+
],
|
107 |
layout="horizontal",
|
108 |
theme="huggingface",
|
109 |
title="Whisper French Demo 🇫🇷 : Transcribe YouTube",
|
|
|
118 |
with demo:
|
119 |
gr.TabbedInterface([mf_transcribe, yt_transcribe], ["Transcribe Audio", "Transcribe YouTube"])
|
120 |
|
121 |
+
# demo.launch(server_name="0.0.0.0", debug=True, share=True)
|
122 |
demo.launch(enable_queue=True)
|