code: def evaluate():
      global model, train_set, metric_classnames
  
      if model is None:
          return "Model is not yet loaded. Please try again later.", 400
  
      if train_set is None:
          return "Unable to evaluate. 'train_set' is not provided", 400
  
      query = request.json
  
      query_metrics = query.get("metrics")
      rating_threshold = query.get("rating_threshold", 1.0)
      exclude_unknowns = (
          query.get("exclude_unknowns", "true").lower() == "true"
      )  # exclude unknown users/items by default, otherwise specified
      user_based = (
          query.get("user_based", "true").lower() == "true"
      )  # user_based evaluation by default, otherwise specified
  
      if query_metrics is None:
          return "metrics is required", 400
      elif not isinstance(query_metrics, list):
          return "metrics must be an array of metrics", 400
  
      # organize metrics
      metrics = []
      for metric in query_metrics:
          try:
              metrics.append(_safe_eval(metric))
          except:
              return (
                  f"Invalid metric initiation: {metric}.\n"
                  + "Please input correct metrics (e.g., 'RMSE()', 'Recall(k=10)')",
                  400,
              )
  
      rating_metrics, ranking_metrics = BaseMethod.organize_metrics(
          metrics
      )
  
      # read data
      data = []
      data_fpath = "data/feedback.csv"
      if os.path.exists(data_fpath):
          reader = Reader()
          data = reader.read(data_fpath, fmt="UIR", sep=",")
  
      if not len(data):
          raise ValueError("No data available to evaluate the model.")
  
      test_set = Dataset.build(
          data,
          fmt="UIR",
          global_uid_map=train_set.uid_map,
          global_iid_map=train_set.iid_map,
          exclude_unknowns=exclude_unknowns,
      )
  
      # evaluation
      result = BaseMethod.eval(
          model=model,
          train_set=train_set,
          test_set=test_set,
          val_set=None,
          rating_threshold=rating_threshold,
          exclude_unknowns=exclude_unknowns,
          rating_metrics=rating_metrics,
          ranking_metrics=ranking_metrics,
          user_based=user_based,
          verbose=False,
      )
  
      # response
      response = {
          "result": result.metric_avg_results,
          "query": query,
      }
  
      return jsonify(response), 200
  
file_path: cornac/cornac/serving/app.py
imports: import os
  import sys
  import inspect
  from datetime import datetime, timezone
  from csv import writer
  from cornac.data import Dataset, Reader
  from cornac.eval_methods import BaseMethod
  from cornac.metrics import *
label_desc: Use image node_id 8 for calling a global function with example usage: evaluate() and returns: jsonify,  int, str,  int, str,  int, str,  int, str,  int, unknown,  int