Spaces:
Runtime error
Runtime error
AndrewRWilliams
commited on
Commit
•
af31188
1
Parent(s):
e8409fb
Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,10 @@ MAX_FILE_PREFIX_LENGTH = 17
|
|
14 |
|
15 |
model = whisper.load_model("base")
|
16 |
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
def slugify(value, allow_unicode=False):
|
20 |
"""
|
@@ -34,28 +37,44 @@ def slugify(value, allow_unicode=False):
|
|
34 |
|
35 |
async def transcribe(file):
|
36 |
|
37 |
-
|
38 |
-
|
|
|
|
|
39 |
# transcribe_options = dict(beam_size=5, best_of=5, without_timestamps=False)
|
40 |
|
41 |
# result = model.transcribe(file, **transcribe_options)
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
|
|
|
|
|
|
52 |
#subtitles
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
download.append(filePrefix + "-transcript.txt");
|
59 |
|
60 |
return download
|
61 |
|
@@ -65,4 +84,8 @@ with demo:
|
|
65 |
transcript = gr.File(label="transcript")
|
66 |
b1 = gr.Button("Transcrire")
|
67 |
b1.click(transcribe, inputs=audio_file, outputs=transcript)
|
68 |
-
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
model = whisper.load_model("base")
|
16 |
|
17 |
+
try:
|
18 |
+
demo = gr.Blocks(cache_examples=False)
|
19 |
+
except Exception as e:
|
20 |
+
print(e)
|
21 |
|
22 |
def slugify(value, allow_unicode=False):
|
23 |
"""
|
|
|
37 |
|
38 |
async def transcribe(file):
|
39 |
|
40 |
+
try:
|
41 |
+
audio = await whisper.load_audio(file.name)
|
42 |
+
except Exception as e:
|
43 |
+
print(e)
|
44 |
# transcribe_options = dict(beam_size=5, best_of=5, without_timestamps=False)
|
45 |
|
46 |
# result = model.transcribe(file, **transcribe_options)
|
47 |
+
try:
|
48 |
+
result = await model.transcribe(audio)
|
49 |
+
except Exception as e:
|
50 |
+
print(e)
|
51 |
+
|
52 |
+
try:
|
53 |
+
file_path = pathlib.Path(file.name)
|
54 |
+
sourceName = file_path.stem[:MAX_FILE_PREFIX_LENGTH] + file_path.suffix
|
55 |
+
filePrefix = slugify(sourceName, allow_unicode=True)
|
56 |
+
except Exception as e:
|
57 |
+
print(e)
|
58 |
+
|
59 |
+
#write to file
|
60 |
+
try:
|
61 |
+
with open(filePrefix + "-transcript.txt", 'w', encoding="utf-8") as f:
|
62 |
+
f.write(result['text'])
|
63 |
|
64 |
+
except Exception as e:
|
65 |
+
print(e)
|
66 |
+
|
67 |
#subtitles
|
68 |
+
try:
|
69 |
+
with open(filePrefix + "-subs.srt", 'w', encoding="utf-8") as srt:
|
70 |
+
write_srt(result["segments"], file=srt)
|
71 |
+
|
72 |
+
download = []
|
73 |
+
download.append(filePrefix + "-subs.srt");
|
74 |
+
download.append(filePrefix + "-transcript.txt");à
|
75 |
|
76 |
+
except Exception as e:
|
77 |
+
print(e)
|
|
|
78 |
|
79 |
return download
|
80 |
|
|
|
84 |
transcript = gr.File(label="transcript")
|
85 |
b1 = gr.Button("Transcrire")
|
86 |
b1.click(transcribe, inputs=audio_file, outputs=transcript)
|
87 |
+
|
88 |
+
try:
|
89 |
+
demo.launch()
|
90 |
+
except Exception as e:
|
91 |
+
print(e)
|