Spaces:
Runtime error
Runtime error
jpdiazpardo
commited on
Commit
•
b8b135b
1
Parent(s):
2809c68
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
|
|
1 |
import torch
|
2 |
from transformers import pipeline
|
3 |
-
|
4 |
|
5 |
MODEL_NAME = "openai/whisper-medium"
|
6 |
BATCH_SIZE = 8
|
@@ -14,28 +15,6 @@ pipe = pipeline(
|
|
14 |
device=device,
|
15 |
)
|
16 |
|
17 |
-
|
18 |
-
# Copied from https://github.com/openai/whisper/blob/c09a7ae299c4c34c5839a76380ae407e7d785914/whisper/utils.py#L50
|
19 |
-
def format_timestamp(seconds: float, always_include_hours: bool = False, decimal_marker: str = "."):
|
20 |
-
if seconds is not None:
|
21 |
-
milliseconds = round(seconds * 1000.0)
|
22 |
-
|
23 |
-
hours = milliseconds // 3_600_000
|
24 |
-
milliseconds -= hours * 3_600_000
|
25 |
-
|
26 |
-
minutes = milliseconds // 60_000
|
27 |
-
milliseconds -= minutes * 60_000
|
28 |
-
|
29 |
-
seconds = milliseconds // 1_000
|
30 |
-
milliseconds -= seconds * 1_000
|
31 |
-
|
32 |
-
hours_marker = f"{hours:02d}:" if always_include_hours or hours > 0 else ""
|
33 |
-
return f"{hours_marker}{minutes:02d}:{seconds:02d}{decimal_marker}{milliseconds:03d}"
|
34 |
-
else:
|
35 |
-
# we have a malformed timestamp so just return it as is
|
36 |
-
return seconds
|
37 |
-
|
38 |
-
|
39 |
def transcribe(file, task, return_timestamps):
|
40 |
outputs = pipe(file, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=return_timestamps)
|
41 |
text = outputs["text"]
|
|
|
1 |
+
import gradio as gr
|
2 |
import torch
|
3 |
from transformers import pipeline
|
4 |
+
from timestamp import format_timestamp
|
5 |
|
6 |
MODEL_NAME = "openai/whisper-medium"
|
7 |
BATCH_SIZE = 8
|
|
|
15 |
device=device,
|
16 |
)
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
def transcribe(file, task, return_timestamps):
|
19 |
outputs = pipe(file, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=return_timestamps)
|
20 |
text = outputs["text"]
|