Skip to content

Instantly share code, notes, and snippets.

@PalomaRS
Last active December 28, 2018 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PalomaRS/5b7f8e2a29dea282e15e5b6a04f53baa to your computer and use it in GitHub Desktop.
Save PalomaRS/5b7f8e2a29dea282e15e5b6a04f53baa to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"collapsed": true,
"trusted": false
},
"cell_type": "code",
"source": "import requests\n\n# This function will pass your text to the machine learning model\n# and return the top result with the highest confidence\ndef classify(text):\n key = \"4d498320-036e-11e9-b3bd-230993bd7b325388d668-8f62-4acb-bc8e-38a9592e0d61\"\n url = \"https://machinelearningforkids.co.uk/api/scratch/\"+ key + \"/classify\"\n\n response = requests.get(url, params={ \"data\" : text })\n\n if response.ok:\n responseData = response.json()\n topMatch = responseData[0]\n return topMatch\n else:\n response.raise_for_status()\n\n\ndef answer_question():\n question = input(\"> \")\n answer = classify(question)\n answerclass = answer[\"class_name\"]\n if answerclass == \"Alimentacion\":\n print (\"Depende de la especie de buho. Algunos buhos comen arañas y otros invertebrados. Otros incluso pequeños mamíferos como ratones\")\n elif answerclass == \"Distribucion\":\n print (\"Algunos buhos viven en desiertos, otros en bosques. También habitan zonas Articas\")\n elif answerclass == \"Esperanza_de_vida\":\n print (\"Un búho salvaje puede vivir hasta un máximo de 20 años, pero un búho en cautividad puede superar sin problemas los 50 años de edad. \")\n elif answerclass == \"Especies\":\n print (\"Búho es el nombre común de aves de la familia Strigidae, del orden de los estrigiformes o aves rapaces nocturnas. Habitualmente designa especies que, a diferencia de las lechuzas, tienen plumas alzadas que parecen orejas y presentan una coloración amarilla o naranja en el iris.\")\n elif answerclass == \"Dimensiones\":\n print (\"El tamaño varía según la especie, el más pequeño es el mochuelo que mide 13,5 cm\")\n \nprint (\"¿Qué te gustaría saber de los búhos?\")\n \nwhile True:\n answer_question() ",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"mimetype": "text/x-python",
"nbconvert_exporter": "python",
"name": "python",
"pygments_lexer": "ipython3",
"version": "3.5.4",
"file_extension": ".py",
"codemirror_mode": {
"version": 3,
"name": "ipython"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment