AngelinaZanardi commited on
Commit
4553dcb
·
verified ·
1 Parent(s): fa675d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -28,7 +28,7 @@ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
28
  print(f"Bruker enhet: {device}")
29
 
30
  @spaces.GPU(duration=60 * 2)
31
- def pipe(file, return_timestamps=False,lang="no"):
32
  asr = pipeline(
33
  task="automatic-speech-recognition",
34
  model=MODEL_NAME,
@@ -52,7 +52,7 @@ def format_output(text):
52
  text = re.sub(r'(\.{3,}|[.!:?])', lambda m: m.group() + '<br>', text)
53
  return text
54
 
55
- def transcribe(file, return_timestamps=False,lang="no"):
56
 
57
  waveform, sample_rate = torchaudio.load(file)
58
  audio_duration = waveform.size(1) / sample_rate
@@ -69,12 +69,12 @@ def transcribe(file, return_timestamps=False,lang="no"):
69
  truncated = False
70
 
71
 
72
- if lang=="no":
73
  if not return_timestamps:
74
- text = pipe(file_to_transcribe)["text"]
75
  formatted_text = format_output(text)
76
  else:
77
- chunks = pipe(file_to_transcribe, return_timestamps=True)["chunks"]
78
  text = []
79
  for chunk in chunks:
80
  start_time = time.strftime('%H:%M:%S', time.gmtime(chunk["timestamp"][0])) if chunk["timestamp"][0] is not None else "??:??:??"
 
28
  print(f"Bruker enhet: {device}")
29
 
30
  @spaces.GPU(duration=60 * 2)
31
+ def pipe(file, return_timestamps=False,lang):
32
  asr = pipeline(
33
  task="automatic-speech-recognition",
34
  model=MODEL_NAME,
 
52
  text = re.sub(r'(\.{3,}|[.!:?])', lambda m: m.group() + '<br>', text)
53
  return text
54
 
55
+ def transcribe(file, return_timestamps=False,lang_nn=False):
56
 
57
  waveform, sample_rate = torchaudio.load(file)
58
  audio_duration = waveform.size(1) / sample_rate
 
69
  truncated = False
70
 
71
 
72
+ if not lang_nn:
73
  if not return_timestamps:
74
+ text = pipe(file_to_transcribe, return_timestams=False, lang="no")["text"]
75
  formatted_text = format_output(text)
76
  else:
77
+ chunks = pipe(file_to_transcribe, return_timestamps=True, lang="no")["chunks"]
78
  text = []
79
  for chunk in chunks:
80
  start_time = time.strftime('%H:%M:%S', time.gmtime(chunk["timestamp"][0])) if chunk["timestamp"][0] is not None else "??:??:??"