marquesafonso commited on
Commit
c127215
·
1 Parent(s): 009ce34

change video file validation

Browse files
Files changed (2) hide show
  1. docker-compose.yml +1 -1
  2. main.py +17 -15
docker-compose.yml CHANGED
@@ -4,6 +4,6 @@ services:
4
  context: .
5
  dockerfile: Dockerfile
6
  ports:
7
- - "8000:8000"
8
  volumes:
9
  - .:/app
 
4
  context: .
5
  dockerfile: Dockerfile
6
  ports:
7
+ - "7680:7680"
8
  volumes:
9
  - .:/app
main.py CHANGED
@@ -5,29 +5,31 @@ from utils.process_video import process_video
5
  from utils.zip_response import zip_response
6
  from utils.read_html import read_html
7
 
8
- from fastapi import FastAPI, UploadFile, HTTPException, Form, Depends
9
  from fastapi.responses import HTMLResponse, Response
10
  from fastapi.security import HTTPBasic
11
  from pydantic import BaseModel, field_validator
12
 
 
 
13
  app = FastAPI()
14
  security = HTTPBasic()
15
 
16
- class MP4Video(BaseModel):
17
- video_file: UploadFile
18
 
19
- @property
20
- def filename(self):
21
- return self.video_file.filename
22
- @property
23
- def file(self):
24
- return self.video_file.file
25
 
26
- @field_validator('video_file')
27
- def validate_video_file(cls, self):
28
- if not self.filename.endswith('.mp4'):
29
- raise HTTPException(status_code=500, detail='Invalid video file type. Please upload an MP4 file.')
30
- return self
31
 
32
  class SRTFile(BaseModel):
33
  srt_file: Optional[UploadFile] = None
@@ -71,7 +73,7 @@ async def get_temp_dir():
71
  del dir
72
 
73
  @app.post("/process_video/")
74
- async def process_video_api(video_file: MP4Video = Depends(),
75
  srt_file: SRTFile = Depends(),
76
  task: Optional[str] = Form("transcribe"),
77
  max_words_per_line: Optional[int] = Form(6),
 
5
  from utils.zip_response import zip_response
6
  from utils.read_html import read_html
7
 
8
+ from fastapi import FastAPI, UploadFile, HTTPException, Form, Depends, File
9
  from fastapi.responses import HTMLResponse, Response
10
  from fastapi.security import HTTPBasic
11
  from pydantic import BaseModel, field_validator
12
 
13
+ # TODO: fix error with validation(possibly)
14
+
15
  app = FastAPI()
16
  security = HTTPBasic()
17
 
18
+ # class MP4Video(BaseModel):
19
+ # video_file: UploadFile
20
 
21
+ # @property
22
+ # def filename(self):
23
+ # return self.video_file.filename
24
+ # @property
25
+ # def file(self):
26
+ # return self.video_file.file
27
 
28
+ # # @field_validator('video_file')
29
+ # # def validate_video_file(cls, v):
30
+ # # if "video/" not in v.content_type:
31
+ # # raise HTTPException(status_code=500, detail='Invalid video file type. Please upload an MP4 file.')
32
+ # # return v
33
 
34
  class SRTFile(BaseModel):
35
  srt_file: Optional[UploadFile] = None
 
73
  del dir
74
 
75
  @app.post("/process_video/")
76
+ async def process_video_api(video_file: MP4Video = File(media_type="video"),
77
  srt_file: SRTFile = Depends(),
78
  task: Optional[str] = Form("transcribe"),
79
  max_words_per_line: Optional[int] = Form(6),