-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (40 loc) · 1.31 KB
/
main.py
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
48
49
50
51
from fastapi import Depends, FastAPI
from sqlalchemy.orm import Session
from watchdog.observers import Observer
from vse.model import Load_Yolo_model
from vse.controller import NewImageController
from vse.data_access import crud, entities, schemas
from vse.data_access.database import SessionLocal, engine
entities.Base.metadata.create_all(bind=engine)
from CONFIG import IMAGES_DIR
from typing import List
from vse.request_model import SearchRequestModel
from vse.logic import SearchImageLogic
## Load model
yolo = Load_Yolo_model()
app = FastAPI()
# Dependency
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
@app.get("/")
async def root():
return {"message": "Welcome to our visual search engine..."}
# search by list of keywords and order images by most hits of keywords
@app.post("/search/", response_model=List[str])
async def search(search: SearchRequestModel, db: Session = Depends(get_db)):
sil = SearchImageLogic(search.phrase)
images = sil.process(db)
return images
@app.get("/process")
async def process():
## Start new image event handler
file_handler = NewImageController(IMAGES_DIR, yolo)
result = file_handler.process_all()
if result:
return {"message": "done"}
else:
return {"message": "nothing to process.."}