Skip to content

Commit 4523f70

Browse files
Separate metadata concerns out of main.py.
1 parent a842c5c commit 4523f70

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

app/main.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
from fastapi import FastAPI, File, UploadFile
22
from fire_classifier.predictor import ImagePredictor
3+
from fire_classifier.util.api import API
34

4-
# A: define description for the API endpoints (shown on UI)
5-
endpoint_metadata = [
6-
{
7-
"name": "classify-image",
8-
"description": "Predicts the possibility that a RBG image contains fire.",
9-
},
10-
]
11-
# B: init API
12-
app = FastAPI(
13-
title="DeepFire",
14-
description="A REST API for detecting the presence of fire in an image.",
15-
version="0.0.2",
16-
openapi_tags=endpoint_metadata,
17-
)
5+
# A: init API
6+
app = FastAPI(title=API["title"], description=API["description"],
7+
version=API["version"], openapi_tags=API["endpoints"])
188

19-
# C: init ML inference object
20-
predictor_config_path = "./app/config.yaml"
9+
# B: init ML inference object, and the routes
10+
predictor_config_path = API["config_path"]
2111
predictor = ImagePredictor.init_from_config_path(predictor_config_path)
2212

2313

24-
@app.post("/classify-image/", tags=["classify-image"])
14+
@app.post("/classify-image/", tags=["Detect Fire"])
2515
def create_upload_file(file: UploadFile = File(...)):
2616
"""Predicts the possibility that a RBG image contains fire."""
2717
return predictor.predict_from_file(file.file)

fire_classifier/util/__init__.py

Whitespace-only changes.

fire_classifier/util/api.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
from pathlib import Path
3+
4+
# General info about the API
5+
API_TITLE = "DeepFire"
6+
API_DESCRIPTION = "A REST API for detecting the presence of fire in an image."
7+
API_VERSION = "0.0.2"
8+
9+
# Info about what data users can request.
10+
# These are intended shown on the UI, related only to a specific endpoint.
11+
API_ENDPOINTS = (
12+
{
13+
"name": "Detect Fire",
14+
"description": "Predicts the possibility that a color image contains fire.",
15+
},
16+
)
17+
18+
# Tells the app how to find the config.yaml (for running ML inference)
19+
BASE_DIR = Path(__file__).resolve().parent.parent.parent
20+
CONFIG_PATH = os.path.join(BASE_DIR, 'app', 'config.yaml')
21+
22+
# Wraps all the API metadata as one dictionary
23+
API = {
24+
"title": API_TITLE,
25+
"description": API_DESCRIPTION,
26+
"version": API_VERSION,
27+
"endpoints": API_ENDPOINTS,
28+
"config_path": CONFIG_PATH,
29+
}

0 commit comments

Comments
 (0)