class_docstr: A basic wrapper for machine learning models.
  
  This wrapper should contain the model itself and any additional configuration or
  resources required to run the model/make predictions. It offers a standard interface
  to interact with models regardless of their implementation or framework, e.g. to
  save/load a model to file or make a prediction.
class_docstr_tok: ["A","basic","wrapper","for","machine","learning","models",".","This","wrapper","should","contain","the","model","itself","and","any","additional","configuration","or","resources","required","to","run","the","model\/make","predictions",".","It","offers","a","standard","interface","to","interact","with","models","regardless","of","their","implementation","or","framework",",","e.g",".","to","save\/load","a","model","to","file","or","make","a","prediction","."]
docstr: Create a FastAPI app that can be used to deploy the model.
  
  This needs to be a separate method from deploy so that the API can be tested 
  properly.
docstr_tok: ["Create","a","FastAPI","app","that","can","be","used","to","deploy","the","model",".","This","needs","to","be","a","separate","method","from","deploy","so","that","the","API","can","be","tested","properly","."]
code: def _create_fastapi(self):
      """
      Create a FastAPI app that can be used to deploy the model.
  
      This needs to be a separate method from deploy so that the API can be tested
      properly.
      """
      # TODO: Set version here via version arg. Maybe read _version.txt file or
      #   implement version in __version__.
      app = FastAPI(title="traintool")
      deploy_time = datetime.now()
  
      @app.get("/")
      def index():
          # TODO: Maybe return the same information as in info.yml file,
          #   or experiment ID.
          return {
              "model_name": self.model_name,
              "config": self.config,
              "deploy_time": deploy_time,
          }
  
      @app.post("/predict")
      def predict(predict_request: PredictRequest):
          """Endpoint to classify an image with a deployed model"""
  
          start_time = datetime.now()
  
          # Convert image to numpy array (is list of lists, i.e. what
          # array.tolist() prints out).
          # TODO: Accept image files and paths to images online.
          # TODO: Think about which other parameters to include in predict_request.
          img_arr = np.asarray(predict_request.image)
  
          # Run through model.
          result = self.predict(img_arr)
  
          # Convert numpy arrays in result dict to lists.
          for key, value in result.items():
              try:
                  result[key] = value.tolist()
              except AttributeError:
                  pass  # not an array
  
          result["runtime"] = str(datetime.now() - start_time)
          return result
  
      return app
  
file_path: traintool/traintool/model_wrapper.py
imports: from pathlib import Path
  from fastapi import FastAPI
  import uvicorn
  import numpy
  from abc import ABC, abstractmethod
  from datetime import datetime
  from pydantic import BaseModel
label_desc: Use image node_id 6 for calling the ModelWrapper obj's underlying member method code with example usage: obj._create_fastapi() and returns: app, dict, result