Improve REST API

This commit is contained in:
Andras Schmelczer 2022-06-03 19:29:48 +02:00
parent 6acfb6819e
commit 72e4950cd1
31 changed files with 343 additions and 1678906 deletions

View file

@ -33,18 +33,18 @@
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[38;5;226m2022-05-28 15:02:20,852 | WARNING | Environment variable ENVIRONMENT is not set, defaulting to development mode ‼️\u001b[0m\n",
"\u001b[38;5;39m2022-05-28 15:02:20,853 | INFO | Options: configured ✅\u001b[0m\n",
"\u001b[38;5;39m2022-05-28 15:02:21,168 | INFO | Latest version of small-domain-prediction-v2 is 8 (from versions: 3, 4, 5, 6, 7, 8)\u001b[0m\n",
"\u001b[38;5;39m2022-05-28 15:02:21,169 | INFO | File small-domain-prediction-v2-8 found in cache\u001b[0m\n"
"\u001b[38;5;226m2022-05-28 18:17:13,344 | WARNING | Environment variable ENVIRONMENT is not set, defaulting to development mode ‼️\u001b[0m\n",
"\u001b[38;5;39m2022-05-28 18:17:13,346 | INFO | Options: configured ✅\u001b[0m\n",
"\u001b[38;5;39m2022-05-28 18:17:13,694 | INFO | Latest version of small-domain-prediction is 10 (from versions: 9, 10)\u001b[0m\n",
"\u001b[38;5;39m2022-05-28 18:17:13,694 | INFO | File small-domain-prediction-10 found in cache\u001b[0m\n"
]
}
],
"source": [
"@GreatAI.deploy\n",
"@use_model(\"small-domain-prediction-v2\", version=\"latest\")\n",
"@use_model(\"small-domain-prediction\", version=\"latest\")\n",
"def predict_domain(\n",
" text: str, model: Pipeline, target_confidence: int = 20\n",
" text: str, model: Pipeline, target_confidence: int = 50\n",
") -> List[ClassificationOutput]:\n",
" \"\"\"\n",
" Predict the scientific domain of the input text.\n",
@ -52,7 +52,7 @@
" \"\"\"\n",
" assert 0 <= target_confidence <= 100, \"invalid argument\"\n",
"\n",
" preprocessed = re.sub(r\"[^a-zA-Z ]\", \"\", clean(text, convert_to_ascii=True))\n",
" preprocessed = re.sub(r\"[^a-zA-Z\\s]\", \"\", clean(text, convert_to_ascii=True))\n",
" features = model.named_steps[\"vectorizer\"].transform([preprocessed])\n",
" prediction = model.named_steps[\"classifier\"].predict_proba(features)[0]\n",
"\n",
@ -99,12 +99,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
"{'created': '2022-05-28T13:02:22.035886',\n",
" 'evaluation': None,\n",
" 'evaluation_id': 'c035d78e-dea9-415f-8f93-0dc4cd8dd7b5',\n",
"{'created': '2022-05-28T16:17:14.581693',\n",
" 'exception': None,\n",
" 'execution_time_ms': 94.814,\n",
" 'logged_values': {'arg:predict_domain:target_confidence': 20,\n",
" 'execution_time_ms': 93.638,\n",
" 'feedback': None,\n",
" 'logged_values': {'arg:predict_domain:target_confidence': 50,\n",
" 'arg:predict_domain:text': '\\n'\n",
" ' State-of-the-art methods for zero-shot visual recognition formulate '\n",
" 'learning as a joint embedding problem of images and side information. '\n",
@ -125,10 +124,11 @@
" 'outperforms the attribute-based state-of-the-art for zero-shot '\n",
" 'classification on the CaltechUCSD Birds 200-2011 dataset. ',\n",
" 'arg:predict_domain:text:length': 1236},\n",
" 'models': [{'key': 'small-domain-prediction-v2', 'version': 8}],\n",
" 'models': [{'key': 'small-domain-prediction', 'version': 10}],\n",
" 'output': [{'confidence': 99.0,\n",
" 'explanation': ['information', 'model', 'learning', 'proposed', 'image'],\n",
" 'label': 'Computer Science'}]}\n"
" 'label': 'Computer Science'}],\n",
" 'trace_id': 'd35fcb96-0a95-45f8-93e4-8967160b17dd'}\n"
]
}
],
@ -140,7 +140,7 @@
"\n",
"from pprint import pprint\n",
"\n",
"pprint(result.dict(), width=120)"
"# pprint(result.dict(), width=120)"
]
}
],