{"id":3469,"date":"2022-10-03T14:43:30","date_gmt":"2022-10-03T05:43:30","guid":{"rendered":"https:\/\/aiacademy.jp\/media\/?p=3469"},"modified":"2025-06-03T10:59:56","modified_gmt":"2025-06-03T01:59:56","slug":"gradio%e3%81%a8%e3%81%af%ef%bc%9f-python%e3%81%a7%e6%a9%9f%e6%a2%b0%e5%ad%a6%e7%bf%92web%e3%82%a2%e3%83%97%e3%83%aa%e3%82%b1%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92%e3%82%b5%e3%82%af%e3%83%83","status":"publish","type":"post","link":"https:\/\/aiacademy.jp\/media\/?p=3469","title":{"rendered":"Gradio\u3068\u306f\uff1f Python\u3067\u6a5f\u68b0\u5b66\u7fd2Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u30b5\u30af\u30c3\u3068\u4f5c\u308d\u3046\uff01"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<div class=\"toc\">    <div id=\"toc_container\" class=\"sgb-toc--no-bullets js-smooth-scroll\" data-dialog-title=\"Table of Contents\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <span><\/span>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-0\">Gradio\u3068\u306f<\/a>      <\/li>      <li>        <a href=\"#i-1\">Gradio\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/a>      <\/li>      <li>        <a href=\"#i-2\">Gradio\u306e\u4f7f\u3044\u65b9<\/a>      <\/li>      <li>        <a href=\"#i-3\">\u304a\u307f\u304f\u3058\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308d\u3046<\/a>      <\/li>      <li>        <a href=\"#i-4\">\u3010\u7121\u6599\u52d5\u753b\uff1a\u500d\u901f\u3067\u5b66\u3076\uff01\u751f\u6210AI\u3092\u6d3b\u7528\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u52c9\u5f37\u6cd5\uff08\u77ed\u7e2e\u7248\uff09\u3011<\/a>      <\/li>      <li>        <a href=\"#i-5\">\u82b1\u306e\u7a2e\u985e\u3092\u5224\u5b9a\u3059\u308bWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308d\u3046<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-6\">\u307e\u3068\u3081<\/a>      <\/li>    <\/ul>  <\/li>  <li class=\"last\">    <a href=\"#i-7\">Python\u30fbAI Web\u30a2\u30d7\u30ea\u958b\u767a\u30b9\u30ad\u30eb\u3092\u3001\u3082\u3063\u3068\u5b66\u3073\u305f\u3044\u65b9\u3078<\/a>  <\/li><\/ul>\n      \n    <\/div><\/div><div class=\"toc\"><p><\/p>\n<\/div><h2 class=\"wp-block-heading\" id=\"i-0\">Gradio\u3068\u306f<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"498\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.37.09-1024x498.png\" alt=\"\" class=\"wp-image-3472\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.37.09-1024x498.png 1024w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.37.09-300x146.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.37.09-768x374.png 768w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.37.09-1536x747.png 1536w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.37.09-2048x996.png 2048w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.37.09-940x457.png 940w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/figure>\n\n\n\n<p><a href=\"https:\/\/gradio.app\/\" target=\"_blank\" rel=\"noopener nofollow\" title=\"\">Gradio<\/a>\uff08\u30b0\u30e9\u30c7\u30a3\u30aa\uff09\u3068\u306f\u3001\u6a5f\u68b0\u5b66\u7fd2\u30e2\u30c7\u30eb\u306e\u30c7\u30e2\u3092\u884c\u3046Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u7c21\u5358\u306b\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u308bPython\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u3067\u3059\u3002Gradio\u3067\u4f5c\u6210\u3057\u305fWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306f\u3001<a href=\"https:\/\/huggingface.co\/\" target=\"_blank\" rel=\"noopener nofollow\" title=\"\">HuggingFace<\/a>\u306e<a href=\"https:\/\/huggingface.co\/spaces\" target=\"_blank\" rel=\"noopener nofollow\" title=\"\">Spaces<\/a>\u3067\u30a2\u30d7\u30ea\u3092\u516c\u958b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\uff08\u73fe\u6642\u70b9\u3067\u306f\u3001Gradio\u4ee5\u5916\u306b\u3082\u3001<a href=\"https:\/\/streamlit.io\/\" target=\"_blank\" rel=\"noopener nofollow\" title=\"\">Streamlit<\/a>\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u307e\u3059\u3002\uff09<\/p>\n\n\n\n<p>Gradio\u306e\u516c\u5f0f\u30da\u30fc\u30b8\u3088\u308a\u3001\u30c7\u30e2\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u78ba\u8a8d\u3067\u304d\u307e\u3059\u306e\u3067\u3001\u4e00\u5ea6\u78ba\u8a8d\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"486\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.55.51-1024x486.png\" alt=\"\" class=\"wp-image-3473\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.55.51-1024x486.png 1024w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.55.51-300x142.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.55.51-768x364.png 768w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.55.51-1536x729.png 1536w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.55.51-2048x971.png 2048w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-13.55.51-940x446.png 940w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/figure>\n\n\n\n<p><span class=\"keiko_green\">\u3053\u306e\u30b5\u30a4\u30c8\u306f\u3001Python\u3084\u751f\u6210AI\u306a\u3069\u3092\u5b66\u3079\u308b\u30aa\u30f3\u30e9\u30a4\u30f3\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb AI Academy Bootcamp\u304c\u904b\u55b6\u3057\u3066\u3044\u307e\u3059\u3002<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-1\">Gradio\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/h2>\n\n\n\n<p>Gradio\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092pip\u30b3\u30de\u30f3\u30c9\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3060\u3051\u3067\u3059\u3002<br>Mac\u3067\u3059\u3068\u30bf\u30fc\u30df\u30ca\u30eb\u3001Windows\u3067\u3059\u3068\u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u3092\u8d77\u52d5\u3057\u3001\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5165\u529b\u3057\u5b9f\u884c(Enter)\u3057\u3066\u304f\u3060\u3055\u3044\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install gradio<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-2\">Gradio\u306e\u4f7f\u3044\u65b9<\/h2>\n\n\n\n<p>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u306f\u3001Gradio\u3092\u8aad\u307f\u8fbc\u307f\u3001<code>Interface()<\/code>\u306b\u95a2\u6570\u3068\u5165\u529b\u5f62\u5f0f\uff08\u753b\u50cf\u3001\u30c6\u30ad\u30b9\u30c8\u7b49\uff09\u3001\u51fa\u529b\u5f62\u5f0f\u306e3\u3064\u3092\u6e21\u3057<code>launch()<\/code>\u3092\u5b9f\u884c\u3059\u308b\u3068\u3044\u3046\u8a18\u8ff0\u3092\u884c\u3046\u3060\u3051\u3067\u3059\u3002<br>\u8aac\u660e\u3060\u3051\u3067\u3059\u3068\u308f\u304b\u308a\u306b\u304f\u3044\u305f\u3081\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308a\u306a\u304c\u3089\u78ba\u8a8d\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-3\">\u304a\u307f\u304f\u3058\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308d\u3046<\/h2>\n\n\n\n<p>\u307e\u305a\u306fGradio\u3092\u4f7f\u3063\u3066\u4eca\u65e5\u306e\u904b\u52e2\u304c\u8868\u793a\u3055\u308c\u308b\u304a\u307f\u304f\u3058Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308a\u307e\u3059\u3002<br>\u5b9f\u884c\u74b0\u5883\u306fGradio\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u305f<a href=\"https:\/\/aiacademy.jp\/media\/?p=1037\" target=\"_blank\" rel=\"noopener\" title=\"\">Google Colab<\/a>\u3092\u5229\u7528\u3057\u307e\u3059\u3002<br>\u4ee5\u4e0b\u304c\u30b3\u30fc\u30c9\u5168\u4f53\u3067\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import random\nimport gradio as gr\n\ndef get_foturne(your_name):\n    fortune_lists = ['\u5927\u5409', '\u5409', '\u5c0f\u5409', '\u51f6', '\u672b\u5409']\n    fortune_result = random.choice(fortune_lists)\n    return your_name + \"\u3055\u3093\u306e\u4eca\u65e5\u306e\u904b\u52e2\u306f\u30fb\u30fb\u30fb\" + fortune_result + \"\u3067\u3059\"\n\n\ndemo = gr.Interface(fn=get_foturne,\n                    inputs=\"text\",\n                    outputs=\"text\")\ndemo.launch()\n<\/code><\/pre>\n\n\n\n<p>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001URL\u304c\u767a\u884c\u3055\u308c\u307e\u3059\u304c\u3001Colab\u5185\u306b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u306e\u3067\u3001<br>\u305d\u3053\u304b\u3089\u52d5\u4f5c\u306e\u78ba\u8a8d\u304c\u3067\u304d\u307e\u3059\u3002<br>\u540d\u524d\u3092\u5165\u529b\u3059\u308b\u3068\u3001\u904b\u52e2\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"619\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.23.31-1024x619.png\" alt=\"\" class=\"wp-image-3474\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.23.31-1024x619.png 1024w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.23.31-300x181.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.23.31-768x464.png 768w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.23.31-1536x929.png 1536w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.23.31-940x568.png 940w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.23.31.png 2014w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-4\">\u3010\u7121\u6599\u52d5\u753b\uff1a<strong>\u500d\u901f\u3067\u5b66\u3076\uff01\u751f\u6210AI\u3092\u6d3b\u7528\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u52c9\u5f37\u6cd5\uff08\u77ed\u7e2e\u7248\uff09\u3011<\/strong><\/h2>\n\n\n\n<p>\u751f\u6210AI\u3092\u6d3b\u7528\u3057\u3066\u52b9\u7387\u7684\u306b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u5b66\u3076\u65b9\u6cd5\u3092\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002\u751f\u6210AI\u306e\u57fa\u672c\u7684\u306a\u4ed5\u7d44\u307f\u3084\u52b9\u679c\u7684\u306a\u6d3b\u7528\u6cd5\u3001\u6ce8\u610f\u70b9\u306b\u3064\u3044\u3066\u3082\u8a73\u3057\u304f\u8aac\u660e\u3002\u521d\u5fc3\u8005\u5411\u3051\u306e\u5185\u5bb9\u3067\u3059\u304c\u3001<strong><span class=\"keiko_blue\">\u30c7\u30fc\u30bf\u5206\u6790\u3084\u6a5f\u68b0\u5b66\u7fd2\u3092\u5b66\u3073\u305f\u3044\u65b9\u306b\u3082\u5fdc\u7528\u3057\u3066\u9802\u3051\u307e\u3059\u3002<\/span><\/strong>\u305c\u3072\u3054\u89a7\u304f\u3060\u3055\u3044\uff01<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-vimeo wp-block-embed-vimeo wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" src=\"https:\/\/player.vimeo.com\/video\/1069835048?h=e43b17d6de&amp;dnt=1&amp;app_id=122963\" width=\"880\" height=\"495\" frameborder=\"0\" allow=\"autoplay; fullscreen; picture-in-picture; clipboard-write; encrypted-media\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><strong>\u5168\u7de8\u306f\u3001AI Academy\u516c\u5f0fLINE\u3067\u914d\u4fe1\u4e2d\u3067\u3059\u3002<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/lin.ee\/3E4GzWk\" rel=\"nofollow noopener\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" width=\"910\" height=\"517\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/LINE_Buttom.png\" alt=\"\" class=\"wp-image-6799\" style=\"width:158px;height:auto\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/LINE_Buttom.png 910w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/LINE_Buttom-300x170.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/LINE_Buttom-768x436.png 768w\" sizes=\"auto, (max-width: 910px) 100vw, 910px\"><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-5\">\u82b1\u306e\u7a2e\u985e\u3092\u5224\u5b9a\u3059\u308bWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308d\u3046<\/h2>\n\n\n\n<p>\u5148\u307b\u3069\u306f\u3001Gradio\u3092\u4f7f\u3063\u3066\u304a\u307f\u304f\u3058\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308a\u307e\u3057\u305f\u304c\u3001\u6b21\u306f\u6a5f\u68b0\u5b66\u7fd2\u3092\u7528\u3044\u305f\u82b1\u306e\u7a2e\u985e\u3092\u5224\u5b9a\u3059\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308a\u307e\u3059\u3002<br>\u4eca\u56de\u306f<code>scikit-learn<\/code>\u3067\u30cb\u30e5\u30fc\u30e9\u30eb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3092\u7528\u3044\u3066\u82b1\u3092\u5224\u5b9a\u3059\u308b\u30e2\u30c7\u30eb\u3092\u4f5c\u6210\u3057\u3001\u5b66\u7fd2\u6e08\u307f\u30e2\u30c7\u30eb\u3092Gradio\u5185\u304b\u3089\u8aad\u307f\u8fbc\u307f\u52d5\u4f5c\u3055\u305b\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.datasets import load_iris\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.neural_network import MLPClassifier\nimport joblib\nfrom sklearn.metrics import classification_report, accuracy_score\n\n# \u30c7\u30fc\u30bf\u53d6\u5f97\niris = load_iris()\nx, y = iris.data, iris.target\n\n# \u8a13\u7df4\u30c7\u30fc\u30bf\u3068\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u306b\u5206\u5272\nx_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.5, random_state=0)\n\n# solver\u306b\u306f\u78ba\u7387\u7684\u52fe\u914d\u964d\u4e0b\u6cd5(sgd)\u3084adam\u306a\u3069\u304c\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002\nmodel = MLPClassifier(solver=\"sgd\", random_state=0, max_iter=3000)\n\n# \u5b66\u7fd2\nmodel.fit(x_train, y_train)\npred = model.predict(x_test)\n\n# \u5b66\u7fd2\u6e08\u307f\u30e2\u30c7\u30eb\u306e\u4fdd\u5b58\njoblib.dump(model, \"nn.pkl\", compress=True)\n\n\n# \u7cbe\u5ea6\u3068\u8fd1\u85e4\u884c\u5217\u306e\u51fa\u529b\nprint(\"result: \", model.score(x_test, y_test))\nprint(classification_report(y_test, pred))\n<\/code><\/pre>\n\n\n\n<p>\u4e0a\u8a18\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u82b1\u306e\u5224\u5225\u3059\u308b\u5b66\u7fd2\u6e08\u307f\u30e2\u30c7\u30eb\uff08nn.pkl\uff09\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<br>\u3053\u308c\u3092Gradio\u5185\u3067\u547c\u3073\u51fa\u3057\u3001\u82b1\u306e\u5224\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask, render_template, request, flash\nfrom wtforms import Form, FloatField, SubmitField, validators, ValidationError\nimport numpy as np\nimport gradio as gr\nimport joblib\n\n# \u5b66\u7fd2\u6e08\u307f\u30e2\u30c7\u30eb\u3092\u8aad\u307f\u8fbc\u307f\u5229\u7528\u3057\u307e\u3059\ndef predict(parameters):\n    # \u30cb\u30e5\u30fc\u30e9\u30eb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u30e2\u30c7\u30eb\u3092\u8aad\u307f\u8fbc\u307f\n    model = joblib.load('.\/nn.pkl')\n    params = parameters.reshape(1, -1)\n    pred = model.predict(params)\n    return pred\n\n# \u30e9\u30d9\u30eb\u304b\u3089Iris\u306e\u540d\u524d\u3092\u53d6\u5f97\u3057\u307e\u3059\ndef getName(label):\n    print(label)\n    if label == 0:\n        return \"Iris Setosa\"\n    elif label == 1: \n        return \"Iris Versicolor\"\n    elif label == 2: \n        return \"Iris Virginica\"\n    else: \n        return \"Error\"\n\ndef recognition_flower(sepal_length, sepal_width, petal_length, petal_width):\n    x = np.array([int(sepal_length), int(sepal_width), int(petal_length), int(petal_width)])\n    pred = predict(x)\n    irisName = getName(pred)\n    return irisName\n\n\ndemo = gr.Interface(fn=recognition_flower,\n                    inputs=[gr.Textbox(label=\"SepalLength\"),\n                            gr.Textbox(label=\"SepalWidth\"),\n                            gr.Textbox(label=\"PetalLength\"),\n                            gr.Textbox(label=\"PetalWidth\")\n                    ],\n                    outputs=\"text\")\ndemo.launch()\n<\/code><\/pre>\n\n\n\n<p>\u305d\u308c\u305e\u308c4\u3064\u306e\u5165\u529b\u30d5\u30a9\u30fc\u30e0\u306b\u843c\uff08\u304c\u304f\uff09\u306e\u9577\u3055\u3084\u3001\u82b1\u3073\u3089\u306e\u9577\u3055\u306a\u3069\u3092\u6570\u5024\u3092\u5165\u308c\u3066\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3053\u3068\u3067\u3001\u82b1\u306e\u7a2e\u985e\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"474\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.35.08-1024x474.png\" alt=\"\" class=\"wp-image-3475\" style=\"width:808px;height:auto\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.35.08-1024x474.png 1024w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.35.08-300x139.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.35.08-768x355.png 768w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.35.08-1536x711.png 1536w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.35.08-2048x947.png 2048w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2022\/10\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2022-10-03-14.35.08-940x435.png 940w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-6\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u77ed\u671f\u9593\u3067\u3001AI\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u4f5c\u308a\u305f\u3044\u65b9\u306b\u306fGradio\u306f\u30aa\u30b9\u30b9\u30e1\u3067\u3059\u3002\u662f\u975e\u30aa\u30ea\u30b8\u30ca\u30eb\u306eAI\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/aiacademy.jp\/texts\/#api\" target=\"_blank\" rel=\"noopener\" title=\"AI Academy\u306eWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u7de8\">AI Academy\u306eWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u7de8<\/a>\u3067\u306f\u3001\u4eca\u56de\u5b66\u3093\u3060Gradio\u306e\u4e3b\u8981\u306a\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u8aac\u660e\u3084\u3001\u30a2\u30d7\u30ea\u306e\u516c\u958b\u65b9\u6cd5\u3001\u3055\u3089\u306b\u306f\u3001Flask\u3084FastAPI\u306a\u3069\u306b\u3064\u3044\u3066\u3082\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002\u305d\u308c\u3089\u306e\u5185\u5bb9\u306b\u3064\u3044\u3066\u3082\u5b66\u3073\u305f\u3044\u65b9\u306f<a href=\"https:\/\/aiacademy.jp\/bootcamp\/\" target=\"_blank\" rel=\"noopener\" title=\"AI Academy Bootcamp\">AI Academy Bootcamp<\/a>\u306e\u53d7\u8b1b\u3082\u691c\u8a0e\u3044\u305f\u3060\u3051\u307e\u3059\u3068\u5e78\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"i-7\">Python\u30fbAI Web\u30a2\u30d7\u30ea\u958b\u767a\u30b9\u30ad\u30eb\u3092\u3001\u3082\u3063\u3068\u5b66\u3073\u305f\u3044\u65b9\u3078<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-8\">\u2728AI\u4eba\u6750\u30b3\u30fc\u30b9 \u53d7\u8b1b\u304a\u7533\u8fbc\u307f\u53d7\u4ed8\u4e2d\uff01<\/h3>\n\n\n\n<p><a href=\"https:\/\/aiacademy.jp\/bootcamp\" target=\"_blank\" rel=\"noreferrer noopener\">AI Academy Bootcamp<\/a>&nbsp;\u3067\u306fAI\u30fb\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u3001\u6a5f\u68b0\u5b66\u7fd2\u3001Web\u30a2\u30d7\u30ea\u958b\u767a\u306e\u5b9f\u8df5\u529b\u3092\u9ad8\u3081\u308b\u5168\uff16\u30b3\u30fc\u30b9\u7d0450\u6642\u9593\u4ee5\u4e0a\u306e\u52d5\u753b\u304c\u898b\u653e\u984c\uff01AI\u306e\u5b66\u7fd2\u306b\u5fc5\u9808\u306ePython\u306e\u5b66\u7fd2\u304b\u3089\u59cb\u307e\u308a\u3001IT\u30ea\u30c6\u30e9\u30b7\u30fc\u3001LLM\u5b66\u7fd2\u306a\u3069\u3001\u76ee\u7684\u306b\u5fdc\u3058\u305f\u5e45\u5e83\u3044\u5206\u91ce\u3092\u30ab\u30d0\u30fc\u3057\u3066\u3044\u307e\u3059\u3002LINE\u516c\u5f0f\u3067\u306f\u3001\u304a\u5f97\u306a\u5272\u5f15\u30af\u30fc\u30dd\u30f3\u3082\u30d7\u30ec\u30bc\u30f3\u30c8\u3057\u3066\u3044\u307e\u3059\uff01<\/p>\n\n\n\n<p><strong>\u5358\u72ec\u3067\u5b66\u3076\u3088\u308a\u3001\u5168\u30b3\u30fc\u30b9\u3092\u4e00\u6c17\u306b\u5b66\u3076\u3053\u3068\u3067\u5f97\u3089\u308c\u308b\u300c\u5b66\u7fd2\u30b7\u30ca\u30b8\u30fc\u52b9\u679c\u300d\u304c\u7279\u9577\u3002<\/strong><br>\u57fa\u790e\u304b\u3089\u5fdc\u7528\u307e\u3067\u3001\u30c7\u30fc\u30bf\u5206\u6790\u3068AI\u958b\u767a\u306e\u30b9\u30ad\u30eb\u3092\u52b9\u7387\u3088\u304f\u8eab\u306b\u3064\u3051\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/lin.ee\/3E4GzWk\" target=\"_blank\" rel=\" noreferrer noopener nofollow\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"349\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-1024x349.png\" alt=\"\" class=\"wp-image-7228\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-1024x349.png 1024w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-300x102.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-768x261.png 768w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-1536x523.png 1536w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-2048x697.png 2048w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-940x320.png 940w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6b21 Gradio\u3068\u306f Gradio\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b Gradio\u306e\u4f7f\u3044\u65b9 \u304a\u307f\u304f\u3058\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308d\u3046 \u3010\u7121\u6599\u52d5\u753b\uff1a\u500d\u901f\u3067\u5b66\u3076\uff01\u751f\u6210AI\u3092\u6d3b\u7528\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u52c9\u5f37\u6cd5\uff08\u77ed\u7e2e\u7248\uff09\u3011 \u82b1\u306e\u7a2e\u985e\u3092\u5224\u5b9a\u3059\u308bWeb\u30a2\u30d7\u30ea\u30b1 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":6030,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128,176,130],"tags":[],"class_list":{"0":"post-3469","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-ai-academy","8":"category-sklearn","9":"category-130"},"_links":{"self":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/3469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3469"}],"version-history":[{"count":29,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/3469\/revisions"}],"predecessor-version":[{"id":7344,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/3469\/revisions\/7344"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/media\/6030"}],"wp:attachment":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}