File tree Expand file tree Collapse file tree 5 files changed +36
-2
lines changed
Expand file tree Collapse file tree 5 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ __pycache__/
1313# Keras Models
1414* model /*
1515
16+ # Images Downloaded for Testing
17+ * .jpg
18+ * .jpeg
19+ * .png
20+
1621# Distribution / packaging
1722.Python
1823build /
Original file line number Diff line number Diff line change 1515predictor = ImagePredictor .init_from_config_path (predictor_config_path )
1616
1717
18- @app .post ("/classify-image /" , tags = ["Detect Fire in an Image" ])
19- def create_upload_file (file : UploadFile = File (...)):
18+ @app .post ("/detect-fire /" , tags = ["Detect Fire in an Image" ])
19+ def make_prediction (file : UploadFile = File (...)):
2020 """Predicts the possibility that a RBG image contains fire."""
2121 return predictor .predict_from_file (file .file )
Original file line number Diff line number Diff line change 1+ import unittest
2+
3+ from fastapi .testclient import TestClient
4+ import tensorflow as tf
5+
6+ from app .main import app
7+
8+ client = TestClient (app )
9+
10+ class ClassifierAPITest (unittest .TestCase ):
11+
12+ TEST_COLOR_IMG_URL = "https://storage.googleapis.com/download.tensorflow.org/example_images/592px-Red_sunflower.jpg"
13+
14+ def test_make_prediction_normal (self ):
15+ '''Client submits a RGB image and gets a valid response.'''
16+ # A: get image
17+ image_path = tf .keras .utils .get_file (
18+ origin = self .TEST_COLOR_IMG_URL ,
19+ cache_dir = "." , cache_subdir = "."
20+ )
21+ with open (image_path , 'rb' ) as f :
22+ # B: format a mock request
23+ files = {"file" : (f .name , f , "multipart/form-data" )}
24+ # C: make a request, and verify a valid prediction is returned
25+ response = client .post (
26+ '/detect-fire' , files = files
27+ )
28+ assert response .status_code == 307
Original file line number Diff line number Diff line change @@ -4,4 +4,5 @@ fastapi==0.49.0
44opencv-python-headless == 4.5.3.56
55PyYAML == 5.3
66uvicorn
7+ pytest == 6.2.5
78python-multipart
You can’t perform that action at this time.
0 commit comments