Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from transformers import pipeline
|
|
5 |
from huggingface_hub import model_info
|
6 |
|
7 |
|
8 |
-
MODEL_NAME = "biodatlab/whisper-th-medium-combined"
|
9 |
lang = "th"
|
10 |
|
11 |
device = 0 if torch.cuda.is_available() else "cpu"
|
@@ -26,7 +26,6 @@ def transcribe(microphone, file_upload):
|
|
26 |
"WARNING: You've uploaded an audio file and used the microphone. "
|
27 |
"The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
|
28 |
)
|
29 |
-
|
30 |
elif (microphone is None) and (file_upload is None):
|
31 |
return "ERROR: You have to either use the microphone or upload an audio file"
|
32 |
|
@@ -36,7 +35,6 @@ def transcribe(microphone, file_upload):
|
|
36 |
|
37 |
return warn_output + text
|
38 |
|
39 |
-
|
40 |
def _return_yt_html_embed(yt_url):
|
41 |
video_id = yt_url.split("?v=")[-1]
|
42 |
HTML_str = (
|
@@ -45,7 +43,6 @@ def _return_yt_html_embed(yt_url):
|
|
45 |
)
|
46 |
return HTML_str
|
47 |
|
48 |
-
|
49 |
def yt_transcribe(yt_url):
|
50 |
yt = pt.YouTube(yt_url)
|
51 |
html_embed_str = _return_yt_html_embed(yt_url)
|
@@ -56,42 +53,37 @@ def yt_transcribe(yt_url):
|
|
56 |
|
57 |
return html_embed_str, text
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
)
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
)
|
93 |
-
|
94 |
-
with demo:
|
95 |
-
gr.TabbedInterface([mf_transcribe, yt_transcribe], ["Transcribe Audio", "Transcribe YouTube"])
|
96 |
-
|
97 |
-
demo.launch(enable_queue=True)
|
|
|
5 |
from huggingface_hub import model_info
|
6 |
|
7 |
|
8 |
+
MODEL_NAME = "biodatlab/whisper-th-medium-combined" # this always needs to stay in line 8 :D sorry for the hackiness
|
9 |
lang = "th"
|
10 |
|
11 |
device = 0 if torch.cuda.is_available() else "cpu"
|
|
|
26 |
"WARNING: You've uploaded an audio file and used the microphone. "
|
27 |
"The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
|
28 |
)
|
|
|
29 |
elif (microphone is None) and (file_upload is None):
|
30 |
return "ERROR: You have to either use the microphone or upload an audio file"
|
31 |
|
|
|
35 |
|
36 |
return warn_output + text
|
37 |
|
|
|
38 |
def _return_yt_html_embed(yt_url):
|
39 |
video_id = yt_url.split("?v=")[-1]
|
40 |
HTML_str = (
|
|
|
43 |
)
|
44 |
return HTML_str
|
45 |
|
|
|
46 |
def yt_transcribe(yt_url):
|
47 |
yt = pt.YouTube(yt_url)
|
48 |
html_embed_str = _return_yt_html_embed(yt_url)
|
|
|
53 |
|
54 |
return html_embed_str, text
|
55 |
|
56 |
+
with gr.Blocks(theme=gr.themes.HuggingFace()) as demo:
|
57 |
+
gr.Markdown(f"# Whisper Demo Thai πΉπ")
|
58 |
+
|
59 |
+
with gr.Tab("Transcribe Audio"):
|
60 |
+
gr.Markdown(
|
61 |
+
f"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the fine-tuned"
|
62 |
+
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and π€ Transformers to transcribe audio files"
|
63 |
+
f" of arbitrary length."
|
64 |
+
)
|
65 |
+
with gr.Row():
|
66 |
+
with gr.Column():
|
67 |
+
audio_mic = gr.Audio(source="microphone", type="filepath", label="Microphone Input")
|
68 |
+
audio_file = gr.Audio(source="upload", type="filepath", label="Audio File Upload")
|
69 |
+
with gr.Column():
|
70 |
+
text_output = gr.Textbox(label="Transcription Output")
|
71 |
+
transcribe_btn = gr.Button("Transcribe")
|
72 |
+
transcribe_btn.click(fn=transcribe, inputs=[audio_mic, audio_file], outputs=text_output)
|
73 |
+
|
74 |
+
with gr.Tab("Transcribe YouTube"):
|
75 |
+
gr.Markdown(
|
76 |
+
f"Transcribe long-form YouTube videos with the click of a button! Demo uses the fine-tuned checkpoint:"
|
77 |
+
f" [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and π€ Transformers to transcribe audio files of"
|
78 |
+
f" arbitrary length."
|
79 |
+
)
|
80 |
+
with gr.Row():
|
81 |
+
with gr.Column():
|
82 |
+
yt_url_input = gr.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL")
|
83 |
+
with gr.Column():
|
84 |
+
yt_html_output = gr.HTML(label="Video")
|
85 |
+
yt_text_output = gr.Textbox(label="Transcription Output")
|
86 |
+
yt_transcribe_btn = gr.Button("Transcribe YouTube Video")
|
87 |
+
yt_transcribe_btn.click(fn=yt_transcribe, inputs=yt_url_input, outputs=[yt_html_output, yt_text_output])
|
88 |
+
|
89 |
+
demo.launch(enable_queue=True)
|
|
|
|
|
|
|
|
|
|