Spaces:
Sleeping
Sleeping
Added file persistence
Browse files
__pycache__/youtubeaudio.cpython-310.pyc
CHANGED
Binary files a/__pycache__/youtubeaudio.cpython-310.pyc and b/__pycache__/youtubeaudio.cpython-310.pyc differ
|
|
__pycache__/youtubeaudio.cpython-39.pyc
ADDED
Binary file (2.4 kB). View file
|
|
main.py
CHANGED
@@ -5,7 +5,7 @@ import subprocess
|
|
5 |
import os
|
6 |
import uuid
|
7 |
import logging
|
8 |
-
import
|
9 |
|
10 |
class Url(BaseModel):
|
11 |
url: str
|
@@ -16,7 +16,7 @@ logging.basicConfig(format=format, level=logging.DEBUG,
|
|
16 |
MODEL=os.environ['model']
|
17 |
|
18 |
app = FastAPI()
|
19 |
-
|
20 |
@app.post("/captions/")
|
21 |
def read_root(url: Url):
|
22 |
# Download wav file and get filename
|
@@ -25,8 +25,9 @@ def read_root(url: Url):
|
|
25 |
filename=ytaudio.filename
|
26 |
# Resample file
|
27 |
ytaudio.resample('16k')
|
28 |
-
# Generate subtitles
|
29 |
-
|
|
|
30 |
logging.info(f'Writing to file {output_file}.vtt')
|
31 |
cmd=['/usr/local/bin/whisper','-m',f'/home/user/root/models/ggml-{MODEL}.bin'
|
32 |
,'-f',filename, '-di', '-of', output_file, '-tr', '-ovtt', '-t', '8']
|
@@ -39,5 +40,5 @@ def read_root(url: Url):
|
|
39 |
raise HTTPException(status_code=500, detail="Whisper translation failed")
|
40 |
with open(output_file+".vtt", 'r') as f:
|
41 |
raw_vtt=f.read()
|
42 |
-
|
43 |
-
|
|
|
5 |
import os
|
6 |
import uuid
|
7 |
import logging
|
8 |
+
from fastapi.staticfiles import StaticFiles
|
9 |
|
10 |
class Url(BaseModel):
|
11 |
url: str
|
|
|
16 |
MODEL=os.environ['model']
|
17 |
|
18 |
app = FastAPI()
|
19 |
+
app.mount("/tracks", StaticFiles(directory="/tmp/holosubs/results"), name="tracks")
|
20 |
@app.post("/captions/")
|
21 |
def read_root(url: Url):
|
22 |
# Download wav file and get filename
|
|
|
25 |
filename=ytaudio.filename
|
26 |
# Resample file
|
27 |
ytaudio.resample('16k')
|
28 |
+
# Generate subtitles
|
29 |
+
captionFilename=str(uuid.uuid4())
|
30 |
+
output_file=os.path.join("/tmp/holosubs/results", captionFilename)
|
31 |
logging.info(f'Writing to file {output_file}.vtt')
|
32 |
cmd=['/usr/local/bin/whisper','-m',f'/home/user/root/models/ggml-{MODEL}.bin'
|
33 |
,'-f',filename, '-di', '-of', output_file, '-tr', '-ovtt', '-t', '8']
|
|
|
40 |
raise HTTPException(status_code=500, detail="Whisper translation failed")
|
41 |
with open(output_file+".vtt", 'r') as f:
|
42 |
raw_vtt=f.read()
|
43 |
+
return {"captions": f"{captionFilename}.vtt"}
|
44 |
+
|