shaders?
Browse files- App/Shaders/Schemas.py +11 -0
- App/Shaders/ShaderRoutes.py +56 -0
- App/Shaders/utils.py +22 -0
- Dockerfile +11 -1
- requirements.txt +12 -1
App/Shaders/Schemas.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List, Optional
|
2 |
+
from pydantic import EmailStr, BaseModel
|
3 |
+
from datetime import date, datetime, time, timedelta
|
4 |
+
|
5 |
+
|
6 |
+
class BaseRequest(BaseModel):
|
7 |
+
image: str
|
8 |
+
|
9 |
+
|
10 |
+
class BaseResponse(BaseModel):
|
11 |
+
result: str
|
App/Shaders/ShaderRoutes.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import APIRouter, status
|
2 |
+
from .Schemas import BaseRequest, BaseResponse
|
3 |
+
from fastapi import FastAPI, HTTPException, Request
|
4 |
+
import os
|
5 |
+
|
6 |
+
# from HuggingChat import getChatBot
|
7 |
+
|
8 |
+
|
9 |
+
import aiofiles
|
10 |
+
from fastapi.responses import StreamingResponse, FileResponse
|
11 |
+
from .utils import make_effect
|
12 |
+
|
13 |
+
shader_router = APIRouter(tags=["Shaders"])
|
14 |
+
|
15 |
+
|
16 |
+
@shader_router.get("/3d-effect")
|
17 |
+
async def shader_3d(image_link: str):
|
18 |
+
return make_effect(image_link=image_link)
|
19 |
+
|
20 |
+
|
21 |
+
@shader_router.get("/shaderOuput/{audio_name}")
|
22 |
+
async def serve_audio(request: Request, audio_name: str):
|
23 |
+
audio_directory = "/tmp/Video"
|
24 |
+
audio_path = os.path.join(audio_directory, audio_name)
|
25 |
+
if not os.path.isfile(audio_path):
|
26 |
+
raise HTTPException(status_code=404, detail="Audio not found")
|
27 |
+
|
28 |
+
range_header = request.headers.get("Range", None)
|
29 |
+
audio_size = os.path.getsize(audio_path)
|
30 |
+
|
31 |
+
if range_header:
|
32 |
+
start, end = range_header.strip().split("=")[1].split("-")
|
33 |
+
start = int(start)
|
34 |
+
end = audio_size if end == "" else int(end)
|
35 |
+
|
36 |
+
headers = {
|
37 |
+
"Content-Range": f"bytes {start}-{end}/{audio_size}",
|
38 |
+
"Accept-Ranges": "bytes",
|
39 |
+
# Optionally, you might want to force download by uncommenting the next line:
|
40 |
+
# "Content-Disposition": f"attachment; filename={audio_name}",
|
41 |
+
}
|
42 |
+
|
43 |
+
content = read_file_range(audio_path, start, end)
|
44 |
+
return StreamingResponse(content, media_type="video/mp4", headers=headers)
|
45 |
+
|
46 |
+
return FileResponse(audio_path, media_type="video/mp4")
|
47 |
+
|
48 |
+
|
49 |
+
async def read_file_range(path, start, end):
|
50 |
+
async with aiofiles.open(path, "rb") as file:
|
51 |
+
await file.seek(start)
|
52 |
+
while True:
|
53 |
+
data = await file.read(1024 * 1024) # read in chunks of 1MB
|
54 |
+
if not data or await file.tell() > end:
|
55 |
+
break
|
56 |
+
yield data
|
App/Shaders/utils.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
os.environ["WINDOW_BACKEND"] = "headless" # Use software rendering
|
4 |
+
os.environ["SKIP_TORCH"] = "1"
|
5 |
+
|
6 |
+
from DepthFlow import DepthFlowScene
|
7 |
+
import uuid
|
8 |
+
|
9 |
+
|
10 |
+
depthflow = DepthFlowScene()
|
11 |
+
|
12 |
+
|
13 |
+
def make_effect(image_link):
|
14 |
+
filename = f"{str(uuid.uuid4())}.mp4"
|
15 |
+
destination = os.path.join("/tmp/Video", filename)
|
16 |
+
depthflow.input(image=image_link)
|
17 |
+
depthflow.main(
|
18 |
+
fps=30,
|
19 |
+
output=destination,
|
20 |
+
quality=1,
|
21 |
+
)
|
22 |
+
return {"file": filename}
|
Dockerfile
CHANGED
@@ -11,7 +11,17 @@ RUN chmod 755 /srv
|
|
11 |
|
12 |
RUN apt-get update && \
|
13 |
apt-get install -y --no-install-recommends \
|
14 |
-
aria2 ffmpeg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
#copy requirements
|
17 |
COPY requirements.txt .
|
|
|
11 |
|
12 |
RUN apt-get update && \
|
13 |
apt-get install -y --no-install-recommends \
|
14 |
+
aria2 ffmpeg libgl1-mesa-dev \
|
15 |
+
libgles2-mesa-dev \
|
16 |
+
libglu1-mesa-dev \
|
17 |
+
freeglut3-dev \
|
18 |
+
libglfw3-dev \
|
19 |
+
libglew-dev \
|
20 |
+
libsdl2-dev \
|
21 |
+
libjpeg-dev \
|
22 |
+
libpng-dev \
|
23 |
+
libfreetype6-dev \
|
24 |
+
&& rm -rf /var/lib/apt/lists/*
|
25 |
|
26 |
#copy requirements
|
27 |
COPY requirements.txt .
|
requirements.txt
CHANGED
@@ -24,7 +24,18 @@ bs4
|
|
24 |
strenum
|
25 |
pydub
|
26 |
aiofiles
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
|
29 |
git+https://github.com/snowby666/poe-api-wrapper.git@2c91207598ad930901cb9fb09734705056b7b6a9
|
30 |
-
git+https://github.com/Mbonea-Mjema/ballyregan.git
|
|
|
|
|
|
|
|
|
|
|
|
24 |
strenum
|
25 |
pydub
|
26 |
aiofiles
|
27 |
+
PyOpenGL
|
28 |
+
PyOpenGL_accelerate
|
29 |
+
glfw
|
30 |
+
Pillow
|
31 |
+
numpy
|
32 |
+
broken-source
|
33 |
|
34 |
|
35 |
git+https://github.com/snowby666/poe-api-wrapper.git@2c91207598ad930901cb9fb09734705056b7b6a9
|
36 |
+
git+https://github.com/Mbonea-Mjema/ballyregan.git
|
37 |
+
|
38 |
+
--find-links https://download.pytorch.org/whl/cpu
|
39 |
+
torch
|
40 |
+
torchvision
|
41 |
+
torchaudio
|