langgz commited on
Commit
19d75a6
·
verified ·
1 Parent(s): a9f639a

fix: restore FunClip transcription and multi-segment clipping

Browse files

Use the Hugging Face Paraformer, VAD, and punctuation pipeline with explicit submodel hubs and timestamp generation. Also accept Gradio checkbox labels and interleave FFmpeg concat inputs for multiple clips.

Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -3,16 +3,18 @@ import json
3
  import tempfile
4
  import subprocess
5
  import gradio as gr
6
- import numpy as np
7
- import torch
8
 
9
  from funasr import AutoModel
10
 
11
  model = AutoModel(
12
- model="iic/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-pytorch",
13
  hub="hf",
14
- model_hub="hf",
 
 
 
15
  device="cpu",
 
16
  )
17
 
18
 
@@ -38,7 +40,12 @@ def transcribe_video(video_path, progress=gr.Progress()):
38
 
39
  progress(0.3, desc="Transcribing speech...")
40
  try:
41
- res = model.generate(input=audio_path, batch_size_s=300)
 
 
 
 
 
42
  except Exception as e:
43
  return f"Transcription error: {str(e)}", [], None
44
  finally:
@@ -75,7 +82,7 @@ def clip_video(video_path, sentences_json, selected_indices):
75
 
76
  sentences = json.loads(sentences_json)
77
 
78
- indices = [int(i) for i in selected_indices]
79
  if not indices:
80
  return None, "No segments selected."
81
 
@@ -103,9 +110,8 @@ def clip_video(video_path, sentences_json, selected_indices):
103
  f"[0:a]atrim=start={start:.3f}:end={end:.3f},asetpts=PTS-STARTPTS[a{i}];"
104
  )
105
 
106
- concat_v = "".join(f"[v{i}]" for i in range(len(merged)))
107
- concat_a = "".join(f"[a{i}]" for i in range(len(merged)))
108
- filter_parts.append(f"{concat_v}{concat_a}concat=n={len(merged)}:v=1:a=1[outv][outa]")
109
 
110
  filter_complex = "".join(filter_parts)
111
 
 
3
  import tempfile
4
  import subprocess
5
  import gradio as gr
 
 
6
 
7
  from funasr import AutoModel
8
 
9
  model = AutoModel(
10
+ model="funasr/paraformer-zh",
11
  hub="hf",
12
+ vad_model="funasr/fsmn-vad",
13
+ vad_kwargs={"hub": "hf", "max_single_segment_time": 60000},
14
+ punc_model="funasr/ct-punc",
15
+ punc_kwargs={"hub": "hf"},
16
  device="cpu",
17
+ disable_update=True,
18
  )
19
 
20
 
 
40
 
41
  progress(0.3, desc="Transcribing speech...")
42
  try:
43
+ res = model.generate(
44
+ input=audio_path,
45
+ batch_size_s=300,
46
+ pred_timestamp=True,
47
+ sentence_timestamp=True,
48
+ )
49
  except Exception as e:
50
  return f"Transcription error: {str(e)}", [], None
51
  finally:
 
82
 
83
  sentences = json.loads(sentences_json)
84
 
85
+ indices = [int(str(i).split(":", 1)[0]) for i in selected_indices]
86
  if not indices:
87
  return None, "No segments selected."
88
 
 
110
  f"[0:a]atrim=start={start:.3f}:end={end:.3f},asetpts=PTS-STARTPTS[a{i}];"
111
  )
112
 
113
+ concat_inputs = "".join(f"[v{i}][a{i}]" for i in range(len(merged)))
114
+ filter_parts.append(f"{concat_inputs}concat=n={len(merged)}:v=1:a=1[outv][outa]")
 
115
 
116
  filter_complex = "".join(filter_parts)
117