Commit
·
ab25f71
1
Parent(s):
1aceee0
add transparency pro tip. fix file validation.
Browse files- main.py +23 -7
- static/submit_video.html +1 -1
- utils/process_video.py +0 -1
main.py
CHANGED
|
@@ -2,6 +2,7 @@ from fastapi import FastAPI, UploadFile, HTTPException, File, Form, Depends
|
|
| 2 |
from fastapi.responses import FileResponse, HTMLResponse
|
| 3 |
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
| 4 |
from typing import Optional
|
|
|
|
| 5 |
from utils.process_video import process_video
|
| 6 |
from utils.zip_response import zip_response
|
| 7 |
from utils.api_configs import api_configs
|
|
@@ -29,6 +30,25 @@ logging.basicConfig(filename='main.log',
|
|
| 29 |
format='%(asctime)s %(levelname)s %(message)s',
|
| 30 |
datefmt='%m/%d/%Y %I:%M:%S %p')
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
@app.get("/")
|
| 33 |
async def root():
|
| 34 |
html_content = f"""
|
|
@@ -45,8 +65,8 @@ async def get_form():
|
|
| 45 |
return HTMLResponse(content=html_content)
|
| 46 |
|
| 47 |
@app.post("/process_video/")
|
| 48 |
-
async def process_video_api(video_file:
|
| 49 |
-
srt_file:
|
| 50 |
max_words_per_line: Optional[int] = Form(8),
|
| 51 |
fontsize: Optional[int] = Form(36),
|
| 52 |
font: Optional[str] = Form("FuturaPTHeavy"),
|
|
@@ -55,10 +75,6 @@ async def process_video_api(video_file: UploadFile = File(...),
|
|
| 55 |
username: str = Depends(get_current_user)
|
| 56 |
):
|
| 57 |
try:
|
| 58 |
-
if not str(video_file.filename).endswith('.mp4'):
|
| 59 |
-
raise HTTPException(status_code=400, detail="Invalid Video File type. Please upload an MP4 file.")
|
| 60 |
-
if srt_file.size > 0 and not str(srt_file.filename).endswith('.srt'):
|
| 61 |
-
raise HTTPException(status_code=400, detail="Invalid Subtitles File type. Please upload an SRT file.")
|
| 62 |
logging.info("Creating temporary directories")
|
| 63 |
temp_dir = os.path.join(os.getcwd(),"temp")
|
| 64 |
os.makedirs(temp_dir, exist_ok=True)
|
|
@@ -95,4 +111,4 @@ async def process_video_api(video_file: UploadFile = File(...),
|
|
| 95 |
|
| 96 |
if __name__ == "__main__":
|
| 97 |
# Use Uvicorn to run the application
|
| 98 |
-
uvicorn.run(app, host="127.0.0.1", port=8000)
|
|
|
|
| 2 |
from fastapi.responses import FileResponse, HTMLResponse
|
| 3 |
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
| 4 |
from typing import Optional
|
| 5 |
+
from pydantic import BaseModel, validator
|
| 6 |
from utils.process_video import process_video
|
| 7 |
from utils.zip_response import zip_response
|
| 8 |
from utils.api_configs import api_configs
|
|
|
|
| 30 |
format='%(asctime)s %(levelname)s %(message)s',
|
| 31 |
datefmt='%m/%d/%Y %I:%M:%S %p')
|
| 32 |
|
| 33 |
+
class MP4Video(BaseModel):
|
| 34 |
+
video_file: UploadFile
|
| 35 |
+
|
| 36 |
+
@validator('video_file')
|
| 37 |
+
def validate_video_file(cls, v):
|
| 38 |
+
if not v.filename.endswith('.mp4'):
|
| 39 |
+
raise HTTPException(status_code=500, detail='Invalid video file type. Please upload an MP4 file.')
|
| 40 |
+
return v
|
| 41 |
+
|
| 42 |
+
class SRTFile(BaseModel):
|
| 43 |
+
srt_file: Optional[UploadFile] = None
|
| 44 |
+
|
| 45 |
+
@validator('srt_file')
|
| 46 |
+
def validate_srt_file(cls, v):
|
| 47 |
+
if v.size > 0 and not v.filename.endswith('.srt'):
|
| 48 |
+
raise HTTPException(status_code=422, detail='Invalid subtitle file type. Please upload an SRT file.')
|
| 49 |
+
return v
|
| 50 |
+
|
| 51 |
+
|
| 52 |
@app.get("/")
|
| 53 |
async def root():
|
| 54 |
html_content = f"""
|
|
|
|
| 65 |
return HTMLResponse(content=html_content)
|
| 66 |
|
| 67 |
@app.post("/process_video/")
|
| 68 |
+
async def process_video_api(video_file: MP4Video = Depends(),
|
| 69 |
+
srt_file: SRTFile = Depends(),
|
| 70 |
max_words_per_line: Optional[int] = Form(8),
|
| 71 |
fontsize: Optional[int] = Form(36),
|
| 72 |
font: Optional[str] = Form("FuturaPTHeavy"),
|
|
|
|
| 75 |
username: str = Depends(get_current_user)
|
| 76 |
):
|
| 77 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
logging.info("Creating temporary directories")
|
| 79 |
temp_dir = os.path.join(os.getcwd(),"temp")
|
| 80 |
os.makedirs(temp_dir, exist_ok=True)
|
|
|
|
| 111 |
|
| 112 |
if __name__ == "__main__":
|
| 113 |
# Use Uvicorn to run the application
|
| 114 |
+
uvicorn.run(app, host="127.0.0.1", port=8000)
|
static/submit_video.html
CHANGED
|
@@ -65,7 +65,7 @@
|
|
| 65 |
Max words per line: <input type="number" name="max_words_per_line" value="8"><br>
|
| 66 |
Font size: <input type="number" name="fontsize" value="36"><br>
|
| 67 |
Font: <input type="text" name="font" value="FuturaPTHeavy"><br>
|
| 68 |
-
Background color: <input type="text" name="bg_color" value="#070a13b3"><br>
|
| 69 |
Text color: <input type="text" name="text_color" value="white"><br>
|
| 70 |
<input type="submit">
|
| 71 |
</form>
|
|
|
|
| 65 |
Max words per line: <input type="number" name="max_words_per_line" value="8"><br>
|
| 66 |
Font size: <input type="number" name="fontsize" value="36"><br>
|
| 67 |
Font: <input type="text" name="font" value="FuturaPTHeavy"><br>
|
| 68 |
+
Background color (Pro tip: #00FFFF00 = transparent): <input type="text" name="bg_color" value="#070a13b3"><br>
|
| 69 |
Text color: <input type="text" name="text_color" value="white"><br>
|
| 70 |
<input type="submit">
|
| 71 |
</form>
|
utils/process_video.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# Import necessary modules
|
| 2 |
from utils.transcriber import transcriber
|
| 3 |
from utils.subtitler import subtitler
|
| 4 |
from utils.convert_video_to_audio import convert_video_to_audio
|
|
|
|
|
|
|
| 1 |
from utils.transcriber import transcriber
|
| 2 |
from utils.subtitler import subtitler
|
| 3 |
from utils.convert_video_to_audio import convert_video_to_audio
|