background task
Browse files
main.py
CHANGED
@@ -1,11 +1,19 @@
|
|
1 |
-
import os
|
2 |
import tempfile
|
3 |
import requests
|
4 |
from mimetypes import guess_extension
|
5 |
from PIL import Image
|
6 |
from io import BytesIO
|
7 |
import subprocess
|
8 |
-
from fastapi import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
from typing import List, Optional
|
10 |
import asyncio, aiofiles
|
11 |
from fastapi.responses import StreamingResponse, FileResponse
|
@@ -94,17 +102,18 @@ def make_effect(
|
|
94 |
|
95 |
@app.post("/generate_video")
|
96 |
async def generate_video(
|
|
|
97 |
image_link: str = None,
|
98 |
-
filename: str = "output.mp4",
|
99 |
frame_rate: int = 30,
|
100 |
duration: int = 3,
|
101 |
quality: int = 10,
|
102 |
ssaa: float = 0.75,
|
103 |
raw: bool = True,
|
104 |
):
|
|
|
105 |
try:
|
106 |
-
|
107 |
-
image_link, filename, frame_rate, duration, quality, ssaa, raw
|
108 |
)
|
109 |
return {"output_file": filename}
|
110 |
except Exception as e:
|
|
|
1 |
+
import os, uuid
|
2 |
import tempfile
|
3 |
import requests
|
4 |
from mimetypes import guess_extension
|
5 |
from PIL import Image
|
6 |
from io import BytesIO
|
7 |
import subprocess
|
8 |
+
from fastapi import (
|
9 |
+
FastAPI,
|
10 |
+
UploadFile,
|
11 |
+
File,
|
12 |
+
HTTPException,
|
13 |
+
Response,
|
14 |
+
Request,
|
15 |
+
BackgroundTasks,
|
16 |
+
)
|
17 |
from typing import List, Optional
|
18 |
import asyncio, aiofiles
|
19 |
from fastapi.responses import StreamingResponse, FileResponse
|
|
|
102 |
|
103 |
@app.post("/generate_video")
|
104 |
async def generate_video(
|
105 |
+
background_task: BackgroundTasks,
|
106 |
image_link: str = None,
|
|
|
107 |
frame_rate: int = 30,
|
108 |
duration: int = 3,
|
109 |
quality: int = 10,
|
110 |
ssaa: float = 0.75,
|
111 |
raw: bool = True,
|
112 |
):
|
113 |
+
filename = f"{str(uuid.uuid4())}.mp4"
|
114 |
try:
|
115 |
+
background_task(
|
116 |
+
make_effect, image_link, filename, frame_rate, duration, quality, ssaa, raw
|
117 |
)
|
118 |
return {"output_file": filename}
|
119 |
except Exception as e:
|