-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (36 loc) · 1.25 KB
/
main.py
File metadata and controls
47 lines (36 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import shutil
from fastapi import FastAPI, Response
from fastapi.responses import FileResponse
from fastapi.responses import StreamingResponse
from pydantic import BaseModel
import zipfile, sys, os
from io import BytesIO
import audiogenerate
class Request(BaseModel):
link: str = "https://www.youtube.com/watch?v=I4rtcJnRd6s"
pth_path = os.getenv("PTH_PATH", "")
index_path = os.getenv("INDEX_PATH", "")
audiogenerate.init(pth_path, index_path)
app = FastAPI()
def zipfiles(file_list):
io = BytesIO()
zip_sub_dir = "final_archive"
zip_filename = "%s.zip" % zip_sub_dir
with zipfile.ZipFile(io, mode="w", compression=zipfile.ZIP_DEFLATED) as zip:
for fpath in file_list:
zip.write(fpath)
# close zip
zip.close()
return StreamingResponse(
iter([io.getvalue()]),
media_type="application/x-zip-compressed",
headers={"Content-Disposition": f"attachment;filename=%s" % zip_filename},
)
@app.post("/generate")
async def generate(body: Request):
print(f"starting {body.link}")
vocal, inst = audiogenerate.generateAudioTrack(body.link)
effects = "singing.wav"
shutil.move(inst,"inst.wav")
audiogenerate.addEffects(vocal, effects)
return zipfiles([effects, "inst.wav"])