Spaces:
Running
Running
Jhjoon05
commited on
Commit
Β·
42af183
1
Parent(s):
c4ba943
added attributes to whisper inference and changed variable names
Browse files- app.py +11 -12
- modules/model_Inference.py +3 -1
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from modules.model_Inference import
|
| 3 |
-
import whisper
|
| 4 |
import os
|
| 5 |
from ui.htmls import CSS,MARKDOWN
|
| 6 |
from modules.youtube_manager import get_ytmetas
|
|
@@ -12,7 +11,7 @@ def open_output_folder():
|
|
| 12 |
else:
|
| 13 |
print(f"The folder {folder_path} does not exist.")
|
| 14 |
|
| 15 |
-
|
| 16 |
block = gr.Blocks(css=CSS).queue(api_open=False)
|
| 17 |
|
| 18 |
with block:
|
|
@@ -24,8 +23,8 @@ with block:
|
|
| 24 |
with gr.Row():
|
| 25 |
input_file = gr.File(type="file", label="Upload File here")
|
| 26 |
with gr.Row():
|
| 27 |
-
dd_model = gr.Dropdown(choices=
|
| 28 |
-
dd_lang = gr.Dropdown(choices=["Automatic Detection"]+
|
| 29 |
dd_subformat = gr.Dropdown(["SRT","WebVTT"],value="SRT",label="Subtitle Format")
|
| 30 |
with gr.Row():
|
| 31 |
cb_translate = gr.Checkbox(value=False,label="Translate to English?",interactive=True)
|
|
@@ -35,7 +34,7 @@ with block:
|
|
| 35 |
tb_indicator = gr.Textbox(label="Output")
|
| 36 |
btn_openfolder = gr.Button('π').style(full_width=False)
|
| 37 |
|
| 38 |
-
btn_run.click(fn=
|
| 39 |
btn_openfolder.click(fn=open_output_folder,inputs=[],outputs=[])
|
| 40 |
|
| 41 |
with gr.TabItem("Youtube"): # tab2
|
|
@@ -48,8 +47,8 @@ with block:
|
|
| 48 |
tb_title = gr.Label(label="Youtube Title")
|
| 49 |
tb_description = gr.Textbox(label="Youtube Description",max_lines=15)
|
| 50 |
with gr.Row():
|
| 51 |
-
dd_model = gr.Dropdown(choices=
|
| 52 |
-
dd_lang = gr.Dropdown(choices=["Automatic Detection"]+
|
| 53 |
dd_subformat = gr.Dropdown(choices=["SRT","WebVTT"],value="SRT",label="Subtitle Format")
|
| 54 |
with gr.Row():
|
| 55 |
cb_translate = gr.Checkbox(value=False,label="Translate to English?",interactive=True)
|
|
@@ -59,7 +58,7 @@ with block:
|
|
| 59 |
tb_indicator = gr.Textbox(label="Output")
|
| 60 |
btn_openfolder = gr.Button('π').style(full_width=False)
|
| 61 |
|
| 62 |
-
btn_run.click(fn=
|
| 63 |
tb_youtubelink.change(get_ytmetas,inputs=[tb_youtubelink],outputs=[img_thumbnail,tb_title,tb_description])
|
| 64 |
btn_openfolder.click(fn=open_output_folder,inputs=[],outputs=[])
|
| 65 |
|
|
@@ -67,8 +66,8 @@ with block:
|
|
| 67 |
with gr.Row():
|
| 68 |
mic_input = gr.Microphone(label="Record with Mic",type="filepath",interactive=True)
|
| 69 |
with gr.Row():
|
| 70 |
-
dd_model = gr.Dropdown(choices=
|
| 71 |
-
dd_lang = gr.Dropdown(choices=["Automatic Detection"]+
|
| 72 |
dd_subformat = gr.Dropdown(["SRT","WebVTT"],value="SRT",label="Subtitle Format")
|
| 73 |
with gr.Row():
|
| 74 |
cb_translate = gr.Checkbox(value=False,label="Translate to English?",interactive=True)
|
|
@@ -78,7 +77,7 @@ with block:
|
|
| 78 |
tb_indicator = gr.Textbox(label="Output")
|
| 79 |
btn_openfolder = gr.Button('π').style(full_width=False)
|
| 80 |
|
| 81 |
-
btn_run.click(fn=
|
| 82 |
btn_openfolder.click(fn=open_output_folder,inputs=[],outputs=[])
|
| 83 |
|
| 84 |
block.launch()
|
|
|
|
| 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
|
|
|
|
| 11 |
else:
|
| 12 |
print(f"The folder {folder_path} does not exist.")
|
| 13 |
|
| 14 |
+
whisper_inf = WhisperInference()
|
| 15 |
block = gr.Blocks(css=CSS).queue(api_open=False)
|
| 16 |
|
| 17 |
with block:
|
|
|
|
| 23 |
with gr.Row():
|
| 24 |
input_file = gr.File(type="file", label="Upload File here")
|
| 25 |
with gr.Row():
|
| 26 |
+
dd_model = gr.Dropdown(choices=whisper_inf.available_models,value="large-v2",label="Model")
|
| 27 |
+
dd_lang = gr.Dropdown(choices=["Automatic Detection"]+whisper_inf.available_langs,value="Automatic Detection",label="Language")
|
| 28 |
dd_subformat = gr.Dropdown(["SRT","WebVTT"],value="SRT",label="Subtitle Format")
|
| 29 |
with gr.Row():
|
| 30 |
cb_translate = gr.Checkbox(value=False,label="Translate to English?",interactive=True)
|
|
|
|
| 34 |
tb_indicator = gr.Textbox(label="Output")
|
| 35 |
btn_openfolder = gr.Button('π').style(full_width=False)
|
| 36 |
|
| 37 |
+
btn_run.click(fn=whisper_inf.transcribe_file,inputs=[input_file,dd_model,dd_lang,dd_subformat,cb_translate],outputs=[tb_indicator])
|
| 38 |
btn_openfolder.click(fn=open_output_folder,inputs=[],outputs=[])
|
| 39 |
|
| 40 |
with gr.TabItem("Youtube"): # tab2
|
|
|
|
| 47 |
tb_title = gr.Label(label="Youtube Title")
|
| 48 |
tb_description = gr.Textbox(label="Youtube Description",max_lines=15)
|
| 49 |
with gr.Row():
|
| 50 |
+
dd_model = gr.Dropdown(choices=whisper_inf.available_models,value="large-v2",label="Model")
|
| 51 |
+
dd_lang = gr.Dropdown(choices=["Automatic Detection"]+whisper_inf.available_langs,value="Automatic Detection",label="Language")
|
| 52 |
dd_subformat = gr.Dropdown(choices=["SRT","WebVTT"],value="SRT",label="Subtitle Format")
|
| 53 |
with gr.Row():
|
| 54 |
cb_translate = gr.Checkbox(value=False,label="Translate to English?",interactive=True)
|
|
|
|
| 58 |
tb_indicator = gr.Textbox(label="Output")
|
| 59 |
btn_openfolder = gr.Button('π').style(full_width=False)
|
| 60 |
|
| 61 |
+
btn_run.click(fn=whisper_inf.transcribe_youtube,inputs=[tb_youtubelink,dd_model,dd_lang,dd_subformat,cb_translate],outputs=[tb_indicator])
|
| 62 |
tb_youtubelink.change(get_ytmetas,inputs=[tb_youtubelink],outputs=[img_thumbnail,tb_title,tb_description])
|
| 63 |
btn_openfolder.click(fn=open_output_folder,inputs=[],outputs=[])
|
| 64 |
|
|
|
|
| 66 |
with gr.Row():
|
| 67 |
mic_input = gr.Microphone(label="Record with Mic",type="filepath",interactive=True)
|
| 68 |
with gr.Row():
|
| 69 |
+
dd_model = gr.Dropdown(choices=whisper_inf.available_models,value="large-v2",label="Model")
|
| 70 |
+
dd_lang = gr.Dropdown(choices=["Automatic Detection"]+whisper_inf.available_langs,value="Automatic Detection",label="Language")
|
| 71 |
dd_subformat = gr.Dropdown(["SRT","WebVTT"],value="SRT",label="Subtitle Format")
|
| 72 |
with gr.Row():
|
| 73 |
cb_translate = gr.Checkbox(value=False,label="Translate to English?",interactive=True)
|
|
|
|
| 77 |
tb_indicator = gr.Textbox(label="Output")
|
| 78 |
btn_openfolder = gr.Button('π').style(full_width=False)
|
| 79 |
|
| 80 |
+
btn_run.click(fn=whisper_inf.transcribe_mic,inputs=[mic_input,dd_model,dd_lang,dd_subformat,cb_translate],outputs=[tb_indicator])
|
| 81 |
btn_openfolder.click(fn=open_output_folder,inputs=[],outputs=[])
|
| 82 |
|
| 83 |
block.launch()
|
modules/model_Inference.py
CHANGED
|
@@ -5,11 +5,13 @@ import gradio as gr
|
|
| 5 |
import os
|
| 6 |
from datetime import datetime
|
| 7 |
|
| 8 |
-
class
|
| 9 |
def __init__(self):
|
| 10 |
print("\nInitializing Model..\n")
|
| 11 |
self.current_model_size = "large-v2"
|
| 12 |
self.model = whisper.load_model(self.current_model_size)
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def transcribe_file(self,fileobj
|
| 15 |
,model_size,lang,subformat,istranslate,
|
|
|
|
| 5 |
import os
|
| 6 |
from datetime import datetime
|
| 7 |
|
| 8 |
+
class WhisperInference():
|
| 9 |
def __init__(self):
|
| 10 |
print("\nInitializing Model..\n")
|
| 11 |
self.current_model_size = "large-v2"
|
| 12 |
self.model = whisper.load_model(self.current_model_size)
|
| 13 |
+
self.available_models = whisper.available_models()
|
| 14 |
+
self.available_langs = sorted(list(whisper.tokenizer.LANGUAGES.values()))
|
| 15 |
|
| 16 |
def transcribe_file(self,fileobj
|
| 17 |
,model_size,lang,subformat,istranslate,
|