Skip to content

Commit

Permalink
fix: test case failing issue fix and OCSR parameter description fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed Sep 9, 2023
1 parent 593342c commit e72dcbc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
6 changes: 4 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from fastapi.responses import RedirectResponse
from fastapi_versioning import VersionedFastAPI

from .routers import tools, depict, converters, chem, ocsr
from .routers import tools, depict, converters, chem

# , ocsr
from fastapi.middleware.cors import CORSMiddleware

from prometheus_fastapi_instrumentator import Instrumentator
Expand All @@ -30,7 +32,7 @@
app.include_router(converters.router)
app.include_router(depict.router)
app.include_router(tools.router)
app.include_router(ocsr.router)
# app.include_router(ocsr.router)

app = VersionedFastAPI(
app,
Expand Down
26 changes: 16 additions & 10 deletions app/routers/ocsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from fastapi.responses import JSONResponse
from urllib.request import urlopen
from urllib.parse import urlsplit
from fastapi import Body, APIRouter, status, HTTPException
from fastapi import Body, APIRouter, status, HTTPException, File, UploadFile
from app.modules.decimer import get_predicted_segments_from_file
from app.schemas import HealthCheck
from app.schemas.error import ErrorResponse, BadRequestModel, NotFoundModel
from app.schemas.ocsr_schema import ExtractChemicalInfoResponse
from fastapi import UploadFile
from typing import Annotated

router = APIRouter(
prefix="/ocsr",
Expand Down Expand Up @@ -63,7 +63,7 @@ async def Extract_ChemicalInfo_From_File(
path: str = Body(
None,
embed=True,
description="URL or local file path to the chemical structure depiction image.",
description="Local or Remote path to the image file",
openapi_examples={
"example1": {
"summary": "Cheminformatics - Article example image",
Expand All @@ -75,20 +75,24 @@ async def Extract_ChemicalInfo_From_File(
},
},
),
reference: str = Body(None, embed=True, description="Reference information."),
reference: str = Body(
None,
embed=True,
description="User defined reference information for tracking",
),
img: str = Body(
None,
embed=True,
description="Bytes content of the chemical structure depiction image.",
description="Image: Bytes content of the chemical structure depiction image",
),
):
"""
Detect, segment and convert a chemical structure depiction into a SMILES string using the DECIMER modules.
Parameters:
- **path**: optional if img is provided (str): URL or local file path to the chemical structure depiction image.
- **reference**: optional (str): URL or local file path to the chemical structure depiction image.
- **img**: optional if a valid path is provided (str): URL or local file path to the chemical structure depiction image.
- **path**: optional if img is provided (str): Local or Remote path to the image file.
- **reference**: optional (str): User defined reference information for tracking.
- **img**: optional if a valid path is provided (str): Image: Bytes content of the chemical structure depiction image.
Returns:
- JSONResponse: A JSON response containing the extracted SMILES and the reference (if provided).
Expand Down Expand Up @@ -139,12 +143,14 @@ async def Extract_ChemicalInfo_From_File(
422: {"description": "Unprocessable Entity", "model": ErrorResponse},
},
)
async def extract_chemicalinfo_from_upload(file: UploadFile):
async def extract_chemicalinfo_from_upload(
file: Annotated[UploadFile, File(description="Chemical structure depiction image")],
):
"""
Detect, segment and convert a chemical structure depiction in the uploaded image file into a SMILES string using the DECIMER modules.
Parameters:
- **file**: required (File):
- **file**: required (File): Chemical structure depiction image
Returns:
- JSONResponse: A JSON response containing the extracted SMILES and the reference (if provided).
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_sugars_info(input, response_text, response_code):
"input,response_text, response_code",
[
("OCC(O)C(O)C(O)C(O)C1OC(CO)C(O)C(O)C1O", '"C(C1C(C(C(CO1)O)O)O)O"', 200),
("INVALID_INPUT", "", 500),
("INVALID_INPUT", "", 422),
],
)
def test_remove_linear_sugars(input, response_text, response_code):
Expand Down

0 comments on commit e72dcbc

Please sign in to comment.