-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(routes): reorganize routes and add embedding functionality for t…
…ext and image processing
- Loading branch information
Showing
14 changed files
with
595 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
# FastAPI dev/build outputs | ||
# Python dependencies | ||
__pycache__ | ||
.ruff_cache | ||
|
||
# Python dependencies | ||
.venv | ||
|
||
# Logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
from fastapi import FastAPI | ||
|
||
# from server.dependencies import get_query_token | ||
from server.routes import health, detect, omr, search | ||
|
||
app = FastAPI() # dependencies=[Depends(get_query_token)]) | ||
from server.routes import health, image, text | ||
|
||
# dependencies=[Depends(get_query_token)]) | ||
app = FastAPI() | ||
|
||
app.include_router(health.router) | ||
app.include_router(detect.router) | ||
app.include_router(search.router) | ||
app.include_router(omr.router) | ||
app.include_router(image.detect.router) | ||
app.include_router(image.embedding.router) | ||
app.include_router(text.embedding.router) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from . import detect | ||
from . import embedding | ||
|
||
|
||
__all__ = [detect, embedding] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from fastapi import APIRouter | ||
|
||
|
||
router = APIRouter( | ||
prefix="/image", | ||
tags=["image"], | ||
responses={404: {"description": "Not found"}}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import embedding | ||
|
||
__all__ = [embedding] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from typing import List | ||
from fastapi import HTTPException | ||
from pydantic import BaseModel | ||
from transformers import AutoModel | ||
|
||
from .router import router | ||
|
||
model = AutoModel.from_pretrained("jinaai/jina-clip-v2", trust_remote_code=True) | ||
|
||
|
||
class RequestBody(BaseModel): | ||
id: str | ||
queries: List[str] | ||
|
||
|
||
@router.post("/embedding") | ||
async def get_embedding(request: RequestBody): | ||
try: | ||
truncate_dim = 512 | ||
|
||
embeddings = model.encode_text(request.queries, truncate_dim=truncate_dim) | ||
|
||
return { | ||
"id": request.id, | ||
"embeddings": [[float(x) for x in embedding] for embedding in embeddings], | ||
} | ||
return | ||
except HTTPException as error: | ||
print("API similarity POST", error) | ||
raise error | ||
except Exception as error: | ||
print("API similarity POST", error) | ||
raise HTTPException(status_code=500, detail="Some Unknown Error Found") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from fastapi import APIRouter | ||
|
||
|
||
router = APIRouter( | ||
prefix="/text", | ||
tags=["text"], | ||
responses={404: {"description": "Not found"}}, | ||
) |
Oops, something went wrong.