Spaces:
Running
Running
jhj0517
commited on
Commit
Β·
a0164a7
1
Parent(s):
726af81
better read
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from modules.model_Inference import WhisperInference
|
| 3 |
import os
|
| 4 |
-
from ui.htmls import CSS,MARKDOWN
|
| 5 |
from modules.youtube_manager import get_ytmetas
|
| 6 |
|
| 7 |
def open_output_folder():
|
|
@@ -12,11 +12,11 @@ def open_output_folder():
|
|
| 12 |
print(f"The folder {folder_path} does not exist.")
|
| 13 |
|
| 14 |
def on_change_models(model_size):
|
| 15 |
-
translatable_model = ["large","large-v1","large-v2"]
|
| 16 |
if model_size not in translatable_model:
|
| 17 |
-
return gr.Checkbox.update(visible=False,value=False,interactive=False)
|
| 18 |
else:
|
| 19 |
-
return gr.Checkbox.update(visible=True,value=False,label="Translate to English?",interactive=True)
|
| 20 |
|
| 21 |
whisper_inf = WhisperInference()
|
| 22 |
block = gr.Blocks(css=CSS).queue(api_open=False)
|
|
@@ -24,71 +24,78 @@ block = gr.Blocks(css=CSS).queue(api_open=False)
|
|
| 24 |
with block:
|
| 25 |
with gr.Row():
|
| 26 |
with gr.Column():
|
| 27 |
-
gr.Markdown(MARKDOWN,elem_id="md_project")
|
| 28 |
with gr.Tabs():
|
| 29 |
-
with gr.TabItem("File"):
|
| 30 |
with gr.Row():
|
| 31 |
input_file = gr.Files(type="file", label="Upload File here")
|
| 32 |
with gr.Row():
|
| 33 |
-
dd_model = gr.Dropdown(choices=whisper_inf.available_models,value="large-v2",label="Model")
|
| 34 |
-
dd_lang = gr.Dropdown(choices=["Automatic Detection"]+whisper_inf.available_langs,
|
| 35 |
-
|
|
|
|
| 36 |
with gr.Row():
|
| 37 |
-
cb_translate = gr.Checkbox(value=False,label="Translate to English?",interactive=True)
|
| 38 |
with gr.Row():
|
| 39 |
-
btn_run = gr.Button("GENERATE SUBTITLE FILE",variant="primary")
|
| 40 |
with gr.Row():
|
| 41 |
tb_indicator = gr.Textbox(label="Output")
|
| 42 |
btn_openfolder = gr.Button('π').style(full_width=False)
|
| 43 |
|
| 44 |
-
btn_run.click(fn=whisper_inf.transcribe_file,
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 49 |
with gr.Row():
|
| 50 |
-
tb_youtubelink = gr.Textbox(label="Youtube Link"
|
| 51 |
with gr.Row().style(equal_height=True):
|
| 52 |
with gr.Column():
|
| 53 |
img_thumbnail = gr.Image(label="Youtube Thumbnail")
|
| 54 |
with gr.Column():
|
| 55 |
tb_title = gr.Label(label="Youtube Title")
|
| 56 |
-
tb_description = gr.Textbox(label="Youtube Description",max_lines=15)
|
| 57 |
with gr.Row():
|
| 58 |
-
dd_model = gr.Dropdown(choices=whisper_inf.available_models,value="large-v2",label="Model")
|
| 59 |
-
dd_lang = gr.Dropdown(choices=["Automatic Detection"]+whisper_inf.available_langs,
|
| 60 |
-
|
|
|
|
| 61 |
with gr.Row():
|
| 62 |
-
cb_translate = gr.Checkbox(value=False,label="Translate to English?",interactive=True)
|
| 63 |
with gr.Row():
|
| 64 |
-
btn_run = gr.Button("GENERATE SUBTITLE FILE",variant="primary")
|
| 65 |
with gr.Row():
|
| 66 |
tb_indicator = gr.Textbox(label="Output")
|
| 67 |
btn_openfolder = gr.Button('π').style(full_width=False)
|
| 68 |
|
| 69 |
-
btn_run.click(fn=whisper_inf.transcribe_youtube,
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
with gr.TabItem("Mic"):
|
| 75 |
with gr.Row():
|
| 76 |
-
mic_input = gr.Microphone(label="Record with Mic",type="filepath",interactive=True)
|
| 77 |
with gr.Row():
|
| 78 |
-
dd_model = gr.Dropdown(choices=whisper_inf.available_models,value="large-v2",label="Model")
|
| 79 |
-
dd_lang = gr.Dropdown(choices=["Automatic Detection"]+whisper_inf.available_langs,
|
| 80 |
-
|
|
|
|
| 81 |
with gr.Row():
|
| 82 |
-
cb_translate = gr.Checkbox(value=False,label="Translate to English?",interactive=True)
|
| 83 |
with gr.Row():
|
| 84 |
-
btn_run = gr.Button("GENERATE SUBTITLE FILE",variant="primary")
|
| 85 |
with gr.Row():
|
| 86 |
tb_indicator = gr.Textbox(label="Output")
|
| 87 |
btn_openfolder = gr.Button('π').style(full_width=False)
|
| 88 |
|
| 89 |
-
btn_run.click(fn=whisper_inf.transcribe_mic,
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
block.launch()
|
| 94 |
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from modules.model_Inference import WhisperInference
|
| 3 |
import os
|
| 4 |
+
from ui.htmls import CSS, MARKDOWN
|
| 5 |
from modules.youtube_manager import get_ytmetas
|
| 6 |
|
| 7 |
def open_output_folder():
|
|
|
|
| 12 |
print(f"The folder {folder_path} does not exist.")
|
| 13 |
|
| 14 |
def on_change_models(model_size):
|
| 15 |
+
translatable_model = ["large", "large-v1", "large-v2"]
|
| 16 |
if model_size not in translatable_model:
|
| 17 |
+
return gr.Checkbox.update(visible=False, value=False, interactive=False)
|
| 18 |
else:
|
| 19 |
+
return gr.Checkbox.update(visible=True, value=False, label="Translate to English?", interactive=True)
|
| 20 |
|
| 21 |
whisper_inf = WhisperInference()
|
| 22 |
block = gr.Blocks(css=CSS).queue(api_open=False)
|
|
|
|
| 24 |
with block:
|
| 25 |
with gr.Row():
|
| 26 |
with gr.Column():
|
| 27 |
+
gr.Markdown(MARKDOWN, elem_id="md_project")
|
| 28 |
with gr.Tabs():
|
| 29 |
+
with gr.TabItem("File"): # tab1
|
| 30 |
with gr.Row():
|
| 31 |
input_file = gr.Files(type="file", label="Upload File here")
|
| 32 |
with gr.Row():
|
| 33 |
+
dd_model = gr.Dropdown(choices=whisper_inf.available_models, value="large-v2", label="Model")
|
| 34 |
+
dd_lang = gr.Dropdown(choices=["Automatic Detection"] + whisper_inf.available_langs,
|
| 35 |
+
value="Automatic Detection", label="Language")
|
| 36 |
+
dd_subformat = gr.Dropdown(["SRT", "WebVTT"], value="SRT", label="Subtitle Format")
|
| 37 |
with gr.Row():
|
| 38 |
+
cb_translate = gr.Checkbox(value=False, label="Translate to English?", interactive=True)
|
| 39 |
with gr.Row():
|
| 40 |
+
btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
|
| 41 |
with gr.Row():
|
| 42 |
tb_indicator = gr.Textbox(label="Output")
|
| 43 |
btn_openfolder = gr.Button('π').style(full_width=False)
|
| 44 |
|
| 45 |
+
btn_run.click(fn=whisper_inf.transcribe_file,
|
| 46 |
+
inputs=[input_file, dd_model, dd_lang, dd_subformat, cb_translate], outputs=[tb_indicator])
|
| 47 |
+
btn_openfolder.click(fn=open_output_folder, inputs=[], outputs=[])
|
| 48 |
+
dd_model.change(fn=on_change_models, inputs=[dd_model], outputs=[cb_translate])
|
| 49 |
+
|
| 50 |
+
with gr.TabItem("Youtube"): # tab2
|
| 51 |
with gr.Row():
|
| 52 |
+
tb_youtubelink = gr.Textbox(label="Youtube Link")
|
| 53 |
with gr.Row().style(equal_height=True):
|
| 54 |
with gr.Column():
|
| 55 |
img_thumbnail = gr.Image(label="Youtube Thumbnail")
|
| 56 |
with gr.Column():
|
| 57 |
tb_title = gr.Label(label="Youtube Title")
|
| 58 |
+
tb_description = gr.Textbox(label="Youtube Description", max_lines=15)
|
| 59 |
with gr.Row():
|
| 60 |
+
dd_model = gr.Dropdown(choices=whisper_inf.available_models, value="large-v2", label="Model")
|
| 61 |
+
dd_lang = gr.Dropdown(choices=["Automatic Detection"] + whisper_inf.available_langs,
|
| 62 |
+
value="Automatic Detection", label="Language")
|
| 63 |
+
dd_subformat = gr.Dropdown(choices=["SRT", "WebVTT"], value="SRT", label="Subtitle Format")
|
| 64 |
with gr.Row():
|
| 65 |
+
cb_translate = gr.Checkbox(value=False, label="Translate to English?", interactive=True)
|
| 66 |
with gr.Row():
|
| 67 |
+
btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
|
| 68 |
with gr.Row():
|
| 69 |
tb_indicator = gr.Textbox(label="Output")
|
| 70 |
btn_openfolder = gr.Button('π').style(full_width=False)
|
| 71 |
|
| 72 |
+
btn_run.click(fn=whisper_inf.transcribe_youtube,
|
| 73 |
+
inputs=[tb_youtubelink, dd_model, dd_lang, dd_subformat, cb_translate],
|
| 74 |
+
outputs=[tb_indicator])
|
| 75 |
+
tb_youtubelink.change(get_ytmetas, inputs=[tb_youtubelink],
|
| 76 |
+
outputs=[img_thumbnail, tb_title, tb_description])
|
| 77 |
+
btn_openfolder.click(fn=open_output_folder, inputs=[], outputs=[])
|
| 78 |
+
dd_model.change(fn=on_change_models, inputs=[dd_model], outputs=[cb_translate])
|
| 79 |
|
| 80 |
+
with gr.TabItem("Mic"): # tab3
|
| 81 |
with gr.Row():
|
| 82 |
+
mic_input = gr.Microphone(label="Record with Mic", type="filepath", interactive=True)
|
| 83 |
with gr.Row():
|
| 84 |
+
dd_model = gr.Dropdown(choices=whisper_inf.available_models, value="large-v2", label="Model")
|
| 85 |
+
dd_lang = gr.Dropdown(choices=["Automatic Detection"] + whisper_inf.available_langs,
|
| 86 |
+
value="Automatic Detection", label="Language")
|
| 87 |
+
dd_subformat = gr.Dropdown(["SRT", "WebVTT"], value="SRT", label="Subtitle Format")
|
| 88 |
with gr.Row():
|
| 89 |
+
cb_translate = gr.Checkbox(value=False, label="Translate to English?", interactive=True)
|
| 90 |
with gr.Row():
|
| 91 |
+
btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
|
| 92 |
with gr.Row():
|
| 93 |
tb_indicator = gr.Textbox(label="Output")
|
| 94 |
btn_openfolder = gr.Button('π').style(full_width=False)
|
| 95 |
|
| 96 |
+
btn_run.click(fn=whisper_inf.transcribe_mic,
|
| 97 |
+
inputs=[mic_input, dd_model, dd_lang, dd_subformat, cb_translate], outputs=[tb_indicator])
|
| 98 |
+
btn_openfolder.click(fn=open_output_folder, inputs=[], outputs=[])
|
| 99 |
+
dd_model.change(fn=on_change_models, inputs=[dd_model], outputs=[cb_translate])
|
|
|
|
| 100 |
|
| 101 |
+
block.launch()
|