Skip to content

FunASR-powered video transcription, subtitle generation, and LLM-assisted clipping tool with a local Gradio UI.

update gradio theme

维石61bf09146c2a
diff --git a/funclip/launch.py b/funclip/launch.py
index 192286a..0473770 100644
--- a/funclip/launch.py
+++ b/funclip/launch.py
@@ -11,12 +11,14 @@ from introduction import top_md_1, top_md_2, top_md_3
if __name__ == "__main__":
+
funasr_model = AutoModel(model="iic/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch",
vad_model="damo/speech_fsmn_vad_zh-cn-16k-common-pytorch",
punc_model="damo/punc_ct-transformer_zh-cn-common-vocab272727-pytorch",
spk_model="damo/speech_campplus_sv_zh-cn_16k-common",
)
audio_clipper = VideoClipper(funasr_model)
+ theme = gr.Theme.load("funclip/utils/theme.json")
def audio_recog(audio_input, sd_switch, hotwords, output_dir):
return audio_clipper.recog(audio_input, sd_switch, hotwords, output_dir=output_dir)
@@ -29,9 +31,23 @@ if __name__ == "__main__":
dest_text, start_ost, end_ost, state, dest_spk=video_spk_input, output_dir=output_dir
)
- def mix_recog(video_input, audio_input, sd_switch, hotwords, output_dir):
- # output_dir here is for funasr model generate
- # both relative and absolute paths are OK
+ def mix_recog(video_input, audio_input, hotwords, output_dir):
+ output_dir = output_dir.strip()
+ if not len(output_dir):
+ output_dir = None
+ else:
+ output_dir = os.path.abspath(output_dir)
+ audio_state, video_state = None, None
+ if video_input is not None:
+ res_text, res_srt, video_state = video_recog(
+ video_input, 'No', hotwords, output_dir=output_dir)
+ return res_text, res_srt, video_state, None
+ if audio_input is not None:
+ res_text, res_srt, audio_state = audio_recog(
+ audio_input, 'No', hotwords, output_dir=output_dir)
+ return res_text, res_srt, None, audio_state
+
+ def mix_recog_speaker(video_input, audio_input, hotwords, output_dir):
output_dir = output_dir.strip()
if not len(output_dir):
output_dir = None
@@ -40,16 +56,14 @@ if __name__ == "__main__":
audio_state, video_state = None, None
if video_input is not None:
res_text, res_srt, video_state = video_recog(
- video_input, sd_switch, hotwords, output_dir=output_dir)
+ video_input, 'Yes', hotwords, output_dir=output_dir)
return res_text, res_srt, video_state, None
if audio_input is not None:
res_text, res_srt, audio_state = audio_recog(
- audio_input, sd_switch, hotwords, output_dir=output_dir)
+ audio_input, 'Yes', hotwords, output_dir=output_dir)
return res_text, res_srt, None, audio_state
def mix_clip(dest_text, video_spk_input, start_ost, end_ost, video_state, audio_state, output_dir):
- # output_dir here is for moviepy, vedio saving
- # supposed to be absolute path only
output_dir = output_dir.strip()
if not len(output_dir):
output_dir = None
@@ -72,7 +86,7 @@ if __name__ == "__main__":
)
# gradio interface
- with gr.Blocks() as funclip_service:
+ with gr.Blocks(theme=theme) as funclip_service:
gr.Markdown(top_md_1)
gr.Markdown(top_md_2)
gr.Markdown(top_md_3)
@@ -95,11 +109,13 @@ if __name__ == "__main__":
[audio_input],
label="示例音频 Demo Audio")
with gr.Column():
+ # with gr.Row():
+ # video_sd_switch = gr.Radio(["No", "Yes"], label="👥区分说话人 Get Speakers", value='No')
+ hotwords_input = gr.Textbox(label="🚒热词 Hotwords(多个热词使用空格分隔,仅支持中文热词)")
+ output_dir = gr.Textbox(label="📁文件输出路径 File Output Dir", value=" ")
with gr.Row():
- video_sd_switch = gr.Radio(["No", "Yes"], label="👥是否区分说话人 Recognize Speakers", value='No')
- hotwords_input = gr.Textbox(label="🚒热词 Hotwords")
- output_dir = gr.Textbox(label="文件输出路径 File Output Dir", value=" ")
- recog_button = gr.Button("👂识别 Recognize")
+ recog_button = gr.Button("👂识别 ASR", variant="primary")
+ recog_button2 = gr.Button("👂识别+区分说话人 ASR+SD")
video_text_output = gr.Textbox(label="✏️识别结果 Recognition Result")
video_srt_output = gr.Textbox(label="📖SRT字幕内容 RST Subtitles")
with gr.Column():
@@ -113,7 +129,7 @@ if __name__ == "__main__":
font_color = gr.Radio(["black", "white", "green", "red"], label="🌈字幕颜色 Subtitle Color", value='white')
# font = gr.Radio(["黑体", "Alibaba Sans"], label="字体 Font")
with gr.Row():
- clip_button = gr.Button("✂️裁剪\nClip")
+ clip_button = gr.Button("✂️裁剪\nClip", variant="primary")
clip_subti_button = gr.Button("✂️裁剪+字幕\nClip+Subtitles")
video_output = gr.Video(label="🎥裁剪结果 Video Clipped")
audio_output = gr.Audio(label="🔊裁剪结果 Audio Clipped")
@@ -123,7 +139,13 @@ if __name__ == "__main__":
recog_button.click(mix_recog,
inputs=[video_input,
audio_input,
- video_sd_switch,
+ hotwords_input,
+ output_dir,
+ ],
+ outputs=[video_text_output, video_srt_output, video_state, audio_state])
+ recog_button2.click(mix_recog_speaker,
+ inputs=[video_input,
+ audio_input,
hotwords_input,
output_dir,
],
diff --git a/funclip/utils/theme.json b/funclip/utils/theme.json
new file mode 100644
index 0000000..24bf6ca
--- /dev/null
+++ b/funclip/utils/theme.json
@@ -0,0 +1,333 @@
+{
+ "theme": {
+ "_font": [
+ {
+ "__gradio_font__": true,
+ "name": "Montserrat",
+ "class": "google"
+ },
+ {
+ "__gradio_font__": true,
+ "name": "ui-sans-serif",
+ "class": "font"
+ },
+ {
+ "__gradio_font__": true,
+ "name": "system-ui",
+ "class": "font"
+ },
+ {
+ "__gradio_font__": true,
+ "name": "sans-serif",
+ "class": "font"
+ }
+ ],
+ "_font_mono": [
+ {
+ "__gradio_font__": true,
+ "name": "IBM Plex Mono",
+ "class": "google"
+ },
+ {
+ "__gradio_font__": true,
+ "name": "ui-monospace",
+ "class": "font"
+ },
+ {
+ "__gradio_font__": true,
+ "name": "Consolas",
+ "class": "font"
+ },
+ {
+ "__gradio_font__": true,
+ "name": "monospace",
+ "class": "font"
+ }
+ ],
+ "background_fill_primary": "*neutral_50",
+ "background_fill_primary_dark": "*neutral_950",
+ "background_fill_secondary": "*neutral_50",
+ "background_fill_secondary_dark": "*neutral_900",
+ "block_background_fill": "white",
+ "block_background_fill_dark": "*neutral_800",
+ "block_border_color": "*border_color_primary",
+ "block_border_color_dark": "*border_color_primary",
+ "block_border_width": "0px",
+ "block_border_width_dark": "0px",
+ "block_info_text_color": "*body_text_color_subdued",
+ "block_info_text_color_dark": "*body_text_color_subdued",
+ "block_info_text_size": "*text_sm",
+ "block_info_text_weight": "400",
+ "block_label_background_fill": "*primary_100",
+ "block_label_background_fill_dark": "*primary_600",
+ "block_label_border_color": "*border_color_primary",
+ "block_label_border_color_dark": "*border_color_primary",
+ "block_label_border_width": "1px",
+ "block_label_border_width_dark": "1px",
+ "block_label_margin": "*spacing_md",
+ "block_label_padding": "*spacing_sm *spacing_md",
+ "block_label_radius": "*radius_md",
+ "block_label_right_radius": "0 calc(*radius_lg - 1px) 0 calc(*radius_lg - 1px)",
+ "block_label_text_color": "*primary_500",
+ "block_label_text_color_dark": "*white",
+ "block_label_text_size": "*text_md",
+ "block_label_text_weight": "600",
+ "block_padding": "*spacing_xl calc(*spacing_xl + 2px)",
+ "block_radius": "*radius_lg",
+ "block_shadow": "none",
+ "block_shadow_dark": "none",
+ "block_title_background_fill": "*block_label_background_fill",
+ "block_title_background_fill_dark": "*block_label_background_fill",
+ "block_title_border_color": "none",
+ "block_title_border_color_dark": "none",
+ "block_title_border_width": "0px",
+ "block_title_border_width_dark": "0px",
+ "block_title_padding": "*block_label_padding",
+ "block_title_radius": "*block_label_radius",
+ "block_title_text_color": "*primary_500",
+ "block_title_text_color_dark": "*white",
+ "block_title_text_size": "*text_md",
+ "block_title_text_weight": "600",
+ "body_background_fill": "*background_fill_primary",
+ "body_background_fill_dark": "*background_fill_primary",
+ "body_text_color": "*neutral_800",
+ "body_text_color_dark": "*neutral_100",
+ "body_text_color_subdued": "*neutral_400",
+ "body_text_color_subdued_dark": "*neutral_400",
+ "body_text_size": "*text_md",
+ "body_text_weight": "400",
+ "border_color_accent": "*primary_300",
+ "border_color_accent_dark": "*neutral_600",
+ "border_color_primary": "*neutral_200",
+ "border_color_primary_dark": "*neutral_700",
+ "button_border_width": "*input_border_width",
+ "button_border_width_dark": "*input_border_width",
+ "button_cancel_background_fill": "*button_secondary_background_fill",
+ "button_cancel_background_fill_dark": "*button_secondary_background_fill",
+ "button_cancel_background_fill_hover": "*button_secondary_background_fill_hover",
+ "button_cancel_background_fill_hover_dark": "*button_secondary_background_fill_hover",
+ "button_cancel_border_color": "*button_secondary_border_color",
+ "button_cancel_border_color_dark": "*button_secondary_border_color",
+ "button_cancel_border_color_hover": "*button_cancel_border_color",
+ "button_cancel_border_color_hover_dark": "*button_cancel_border_color",
+ "button_cancel_text_color": "*button_secondary_text_color",
+ "button_cancel_text_color_dark": "*button_secondary_text_color",
+ "button_cancel_text_color_hover": "*button_cancel_text_color",
+ "button_cancel_text_color_hover_dark": "*button_cancel_text_color",
+ "button_large_padding": "*spacing_lg calc(2 * *spacing_lg)",
+ "button_large_radius": "*radius_lg",
+ "button_large_text_size": "*text_lg",
+ "button_large_text_weight": "600",
+ "button_primary_background_fill": "*primary_500",
+ "button_primary_background_fill_dark": "*primary_700",
+ "button_primary_background_fill_hover": "*primary_400",
+ "button_primary_background_fill_hover_dark": "*primary_500",
+ "button_primary_border_color": "*primary_200",
+ "button_primary_border_color_dark": "*primary_600",
+ "button_primary_border_color_hover": "*button_primary_border_color",
+ "button_primary_border_color_hover_dark": "*button_primary_border_color",
+ "button_primary_text_color": "white",
+ "button_primary_text_color_dark": "white",
+ "button_primary_text_color_hover": "*button_primary_text_color",
+ "button_primary_text_color_hover_dark": "*button_primary_text_color",
+ "button_secondary_background_fill": "white",
+ "button_secondary_background_fill_dark": "*neutral_600",
+ "button_secondary_background_fill_hover": "*neutral_100",
+ "button_secondary_background_fill_hover_dark": "*primary_500",
+ "button_secondary_border_color": "*neutral_200",
+ "button_secondary_border_color_dark": "*neutral_600",
+ "button_secondary_border_color_hover": "*button_secondary_border_color",
+ "button_secondary_border_color_hover_dark": "*button_secondary_border_color",
+ "button_secondary_text_color": "*neutral_800",
+ "button_secondary_text_color_dark": "white",
+ "button_secondary_text_color_hover": "*button_secondary_text_color",
+ "button_secondary_text_color_hover_dark": "*button_secondary_text_color",
+ "button_shadow": "*shadow_drop_lg",
+ "button_shadow_active": "*shadow_inset",
+ "button_shadow_hover": "*shadow_drop_lg",
+ "button_small_padding": "*spacing_sm calc(2 * *spacing_sm)",
+ "button_small_radius": "*radius_lg",
+ "button_small_text_size": "*text_md",
+ "button_small_text_weight": "400",
+ "button_transition": "background-color 0.2s ease",
+ "checkbox_background_color": "*background_fill_primary",
+ "checkbox_background_color_dark": "*neutral_800",
+ "checkbox_background_color_focus": "*checkbox_background_color",
+ "checkbox_background_color_focus_dark": "*checkbox_background_color",
+ "checkbox_background_color_hover": "*checkbox_background_color",
+ "checkbox_background_color_hover_dark": "*checkbox_background_color",
+ "checkbox_background_color_selected": "*primary_600",
+ "checkbox_background_color_selected_dark": "*primary_700",
+ "checkbox_border_color": "*neutral_100",
+ "checkbox_border_color_dark": "*neutral_600",
+ "checkbox_border_color_focus": "*primary_500",
+ "checkbox_border_color_focus_dark": "*primary_600",
+ "checkbox_border_color_hover": "*neutral_300",
+ "checkbox_border_color_hover_dark": "*neutral_600",
+ "checkbox_border_color_selected": "*primary_600",
+ "checkbox_border_color_selected_dark": "*primary_700",
+ "checkbox_border_radius": "*radius_sm",
+ "checkbox_border_width": "1px",
+ "checkbox_border_width_dark": "*input_border_width",
+ "checkbox_check": "url(\"data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e\")",
+ "checkbox_label_background_fill": "*button_secondary_background_fill",
+ "checkbox_label_background_fill_dark": "*button_secondary_background_fill",
+ "checkbox_label_background_fill_hover": "*button_secondary_background_fill_hover",
+ "checkbox_label_background_fill_hover_dark": "*button_secondary_background_fill_hover",
+ "checkbox_label_background_fill_selected": "*primary_500",
+ "checkbox_label_background_fill_selected_dark": "*primary_600",
+ "checkbox_label_border_color": "*border_color_primary",
+ "checkbox_label_border_color_dark": "*border_color_primary",
+ "checkbox_label_border_color_hover": "*checkbox_label_border_color",
+ "checkbox_label_border_color_hover_dark": "*checkbox_label_border_color",
+ "checkbox_label_border_width": "*input_border_width",
+ "checkbox_label_border_width_dark": "*input_border_width",
+ "checkbox_label_gap": "*spacing_lg",
+ "checkbox_label_padding": "*spacing_md calc(2 * *spacing_md)",
+ "checkbox_label_shadow": "*shadow_drop_lg",
+ "checkbox_label_text_color": "*body_text_color",
+ "checkbox_label_text_color_dark": "*body_text_color",
+ "checkbox_label_text_color_selected": "white",
+ "checkbox_label_text_color_selected_dark": "*checkbox_label_text_color",
+ "checkbox_label_text_size": "*text_md",
+ "checkbox_label_text_weight": "400",
+ "checkbox_shadow": "none",
+ "color_accent": "*primary_500",
+ "color_accent_soft": "*primary_50",
+ "color_accent_soft_dark": "*neutral_700",
+ "container_radius": "*radius_lg",
+ "embed_radius": "*radius_lg",
+ "error_background_fill": "#fee2e2",
+ "error_background_fill_dark": "*background_fill_primary",
+ "error_border_color": "#fecaca",
+ "error_border_color_dark": "*border_color_primary",
+ "error_border_width": "1px",
+ "error_border_width_dark": "1px",
+ "error_text_color": "#ef4444",
+ "error_text_color_dark": "#ef4444",
+ "font": "'Montserrat', 'ui-sans-serif', 'system-ui', sans-serif",
+ "font_mono": "'IBM Plex Mono', 'ui-monospace', 'Consolas', monospace",
+ "form_gap_width": "0px",
+ "input_background_fill": "white",
+ "input_background_fill_dark": "*neutral_700",
+ "input_background_fill_focus": "*secondary_500",
+ "input_background_fill_focus_dark": "*secondary_600",
+ "input_background_fill_hover": "*input_background_fill",
+ "input_background_fill_hover_dark": "*input_background_fill",
+ "input_border_color": "*neutral_50",
+ "input_border_color_dark": "*border_color_primary",
+ "input_border_color_focus": "*secondary_300",
+ "input_border_color_focus_dark": "*neutral_700",
+ "input_border_color_hover": "*input_border_color",
+ "input_border_color_hover_dark": "*input_border_color",
+ "input_border_width": "0px",
+ "input_border_width_dark": "0px",
+ "input_padding": "*spacing_xl",
+ "input_placeholder_color": "*neutral_400",
+ "input_placeholder_color_dark": "*neutral_500",
+ "input_radius": "*radius_lg",
+ "input_shadow": "*shadow_drop",
+ "input_shadow_dark": "*shadow_drop",
+ "input_shadow_focus": "*shadow_drop_lg",
+ "input_shadow_focus_dark": "*shadow_drop_lg",
+ "input_text_size": "*text_md",
+ "input_text_weight": "400",
+ "layout_gap": "*spacing_xxl",
+ "link_text_color": "*secondary_600",
+ "link_text_color_active": "*secondary_600",
+ "link_text_color_active_dark": "*secondary_500",
+ "link_text_color_dark": "*secondary_500",
+ "link_text_color_hover": "*secondary_700",
+ "link_text_color_hover_dark": "*secondary_400",
+ "link_text_color_visited": "*secondary_500",
+ "link_text_color_visited_dark": "*secondary_600",
+ "loader_color": "*color_accent",
+ "loader_color_dark": "*color_accent",
+ "name": "base",
+ "neutral_100": "#f3f4f6",
+ "neutral_200": "#e5e7eb",
+ "neutral_300": "#d1d5db",
+ "neutral_400": "#9ca3af",
+ "neutral_50": "#f9fafb",
+ "neutral_500": "#6b7280",
+ "neutral_600": "#4b5563",
+ "neutral_700": "#374151",
+ "neutral_800": "#1f2937",
+ "neutral_900": "#111827",
+ "neutral_950": "#0b0f19",
+ "panel_background_fill": "*background_fill_secondary",
+ "panel_background_fill_dark": "*background_fill_secondary",
+ "panel_border_color": "*border_color_primary",
+ "panel_border_color_dark": "*border_color_primary",
+ "panel_border_width": "1px",
+ "panel_border_width_dark": "1px",
+ "primary_100": "#e0e7ff",
+ "primary_200": "#c7d2fe",
+ "primary_300": "#a5b4fc",
+ "primary_400": "#818cf8",
+ "primary_50": "#eef2ff",
+ "primary_500": "#6366f1",
+ "primary_600": "#4f46e5",
+ "primary_700": "#4338ca",
+ "primary_800": "#3730a3",
+ "primary_900": "#312e81",
+ "primary_950": "#2b2c5e",
+ "prose_header_text_weight": "600",
+ "prose_text_size": "*text_md",
+ "prose_text_weight": "400",
+ "radio_circle": "url(\"data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3ccircle cx='8' cy='8' r='3'/%3e%3c/svg%3e\")",
+ "radius_lg": "6px",
+ "radius_md": "4px",
+ "radius_sm": "2px",
+ "radius_xl": "8px",
+ "radius_xs": "1px",
+ "radius_xxl": "12px",
+ "radius_xxs": "1px",
+ "secondary_100": "#ecfccb",
+ "secondary_200": "#d9f99d",
+ "secondary_300": "#bef264",
+ "secondary_400": "#a3e635",
+ "secondary_50": "#f7fee7",
+ "secondary_500": "#84cc16",
+ "secondary_600": "#65a30d",
+ "secondary_700": "#4d7c0f",
+ "secondary_800": "#3f6212",
+ "secondary_900": "#365314",
+ "secondary_950": "#2f4e14",
+ "section_header_text_size": "*text_md",
+ "section_header_text_weight": "400",
+ "shadow_drop": "0 1px 4px 0 rgb(0 0 0 / 0.1)",
+ "shadow_drop_lg": "0 2px 5px 0 rgb(0 0 0 / 0.1)",
+ "shadow_inset": "rgba(0,0,0,0.05) 0px 2px 4px 0px inset",
+ "shadow_spread": "6px",
+ "shadow_spread_dark": "1px",
+ "slider_color": "*primary_500",
+ "slider_color_dark": "*primary_600",
+ "spacing_lg": "6px",
+ "spacing_md": "4px",
+ "spacing_sm": "2px",
+ "spacing_xl": "9px",
+ "spacing_xs": "1px",
+ "spacing_xxl": "12px",
+ "spacing_xxs": "1px",
+ "stat_background_fill": "*primary_300",
+ "stat_background_fill_dark": "*primary_500",
+ "table_border_color": "*neutral_300",
+ "table_border_color_dark": "*neutral_700",
+ "table_even_background_fill": "white",
+ "table_even_background_fill_dark": "*neutral_950",
+ "table_odd_background_fill": "*neutral_50",
+ "table_odd_background_fill_dark": "*neutral_900",
+ "table_radius": "*radius_lg",
+ "table_row_focus": "*color_accent_soft",
+ "table_row_focus_dark": "*color_accent_soft",
+ "text_lg": "16px",
+ "text_md": "14px",
+ "text_sm": "12px",
+ "text_xl": "22px",
+ "text_xs": "10px",
+ "text_xxl": "26px",
+ "text_xxs": "9px"
+ },
+ "version": "0.0.1"
+ }
\ No newline at end of file