{"id":1026,"date":"2020-02-12T23:34:00","date_gmt":"2020-02-12T14:34:00","guid":{"rendered":"http:\/\/aiclub.kr\/?p=1026"},"modified":"2020-02-13T19:03:50","modified_gmt":"2020-02-13T10:03:50","slug":"2-12-ai%ed%81%b4%eb%9f%bd-2%ea%b8%b0-%ed%8c%8c%ec%9d%b4%ec%8d%ac-flask-%ec%9b%b9%ea%b0%9c%eb%b0%9c-%ec%a1%b0%eb%b3%84-%ed%8f%89%ec%9d%bc-5%ec%a3%bc%ec%b0%a8-%eb%aa%a8%ec%9e%84%ed%9b%84%ea%b8%b0","status":"publish","type":"post","link":"https:\/\/aiclub.kr\/?p=1026","title":{"rendered":"2\/12 AI\ud074\ub7fd 2\uae30 \ud30c\uc774\uc36c Flask \uc6f9\uac1c\ubc1c \uc870\ubcc4 \ud3c9\uc77c 5\uc8fc\ucc28 \ubaa8\uc784\ud6c4\uae30"},"content":{"rendered":"\n<p>AI\ud074\ub7fd(<a href=\"https:\/\/l.facebook.com\/l.php?u=http%3A%2F%2Faiclub.kr%2F%3Ffbclid%3DIwAR2zuFpdXkZomRxIrO4au2s6hXMJosCnEGBmylckZi5tNf497dKmWPg7YSA&amp;h=AT0fpsL663Z4SoifACBPs_4Srs0RwsVaneghkDH1tLKPTnvSiazJurpxGCkqLonVwvYXgAG_xyMMXqIfJGP01kEak4sJB7u7qQLdmTgtkXUVgfKoZnDF-ik0JGh8jyW5D7TP8mN0NwBHDCEqxOtJ7h66vfBtcNScsdKsx3c7QUTtChLwUFVXLygfjPht5cXU4Hfki6xWSWSoiF28Sft0Wt0v-zdbPWKs_CNZiPlMHUlLo0VVEYn6NkDvtww7e3eSrucATNsCpwAhndurxhJDrUc_xDEFcu6jTLlboEDrSA0brAAKoY83aLG6DUS2cgNpidVCG-kI4Hc9sbasSCgqgyEbeo0AaTz66A7MWx3jm2S%20target=\">http:\/\/aiclub.kr<\/a>) 5\uc8fc\ucc28 \ubcf4\ucda9 \uc2a4\ud130\ub514\ub97c 2020\ub1442\uc6d412\uc77c \uc218\uc694\uc77c \uc800\ub141 7\uc2dc\ubd80\ud130 10\uc2dc\uae4c\uc9c0 3\uc2dc\uac04 \ubaa8\ub77c\uc5d0\uc11c \uc9c4\ud589 \ud558\uc600\uc2b5\ub2c8\ub2e4.<br>\uc774\ubc88\uc8fc\ub294 \uba3c\uc800 \uac00\ubccd\uac8c \ud15c\ud50c\ub9bf \uac1c\ub150\uc744 \ub2e4\uc2dc\ud55c\ubc88 \ub354 \ubcf5\uc2b5 \ud558\uc600\uc2b5\ub2c8\ub2e4.<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1316\" height=\"640\" src=\"https:\/\/i1.wp.com\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84334851_2867304213331448_3534433436620029952_o.jpg?fit=755%2C367\" alt=\"\" class=\"wp-image-1028\" srcset=\"https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84334851_2867304213331448_3534433436620029952_o.jpg 1316w, https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84334851_2867304213331448_3534433436620029952_o-300x146.jpg 300w, https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84334851_2867304213331448_3534433436620029952_o-755x367.jpg 755w, https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84334851_2867304213331448_3534433436620029952_o-768x373.jpg 768w\" sizes=\"(max-width: 1316px) 100vw, 1316px\" \/><\/figure>\n\n\n\n<p>1. Flask\uc5d0 Request \uac1c\ub150\uc744 \uc774\ud574\ud558\uae30 \uc704\ud574 WordCloud\uc640 Konlpy \uc790\uc5f0\uc5b4 \ucc98\ub9ac\ub97c \uc774\uc6a9\ud574\uc11c \ub124\uc774\ubc84\uc758 \ub274\uc2a4 \uae30\uc0ac\ub97c \uc880 \ub354 \uc815\ud655\ud558\uac8c \uc2dc\uac01\ud654 \ud560 \uc218 \uc788\ub3c4\ub85d \uc2e4\uc2b5\uc744 \uc9c4\ud589\ud558\uc600\uc2b5\ub2c8\ub2e4.\ud558\uc9c0\ub9cc, \uc774\uc804\uc5d0 \uc798 \ub418\uc5c8\ub358 \ubc29\uc2dd\uc5d0 \uc624\ub958\uac00 \uc880 \uc0dd\uaca8\uc11c Konlpy\ub294 \ud3ec\uae30\ub97c \ud588\ub2f5\ub2c8\ub2e4. (\uc2dc\uac04 \uad00\uacc4\uc0c1 \u315c\u315c)\ub4a4\uc5d0 \ub2e4\uc2dc \ub3c4\uc804 \ud558\uae30\ub85c&#8230;<\/p>\n\n\n\n<p>\ud14c\uc2a4\ud2b8 :\u00a0<a rel=\"noreferrer noopener\" href=\"http:\/\/aiclub.pythonanywhere.com\/wordcloud\" target=\"_blank\">http:\/\/aiclub.pythonanywhere.com\/wordcloud<\/a><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li> \/templates\/base.html <\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html>\n&lt;html>\n    &lt;head>\n        &lt;title>BootStrap&lt;\/title>\n        &lt;meta charset=\"utf-8\" \/>\n        &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n        &lt;!-- BootStrap CDN -->\n        &lt;link rel=\"stylesheet\" href=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/4.4.1\/css\/bootstrap.min.css\">\n        &lt;script src=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js\">&lt;\/script>\n        &lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/popper.js\/1.16.0\/umd\/popper.min.js\">&lt;\/script>\n        &lt;script src=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/4.4.1\/js\/bootstrap.min.js\">&lt;\/script>\n        {% block header %}\n        {% endblock %}\n    &lt;\/head>\n    &lt;body>\n        {% block content %}\n        {% endblock %}\n    &lt;\/body>\n&lt;\/html><\/code><\/pre>\n\n\n\n<p> 2) \/templates\/wordcloud.html <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{% extends \"base.html\" %}\n{% block header %}\n&lt;style>\nbody { padding:50px; }\nh1 { text-align:center; }\n&lt;\/style>\n{% endblock %}\n{% block content %}\n&lt;h1>Word Cloud&lt;\/h1>\n&lt;form action=\"\/wordcloud\" method=\"post\" name=\"frm\">\n&lt;div class=\"form-group\">\n  &lt;label for=\"comment\">News Input :&lt;\/label>\n  &lt;textarea class=\"form-control\" rows=\"5\" name=\"content\">{{content}}&lt;\/textarea>\n&lt;\/div>\n&lt;div class=\"form-group\">\n    &lt;input type=\"submit\" class=\"btn btn-primary btn-block btn-lg\">\n&lt;\/div>\n&lt;\/form>\n{% if content %}\n&lt;div>\n    &lt;img src=\"\/static\/wordcloud.png?v={{time}}\">\n&lt;\/div>\n{% endif %}\n{% endblock %}<\/code><\/pre>\n\n\n\n<p> 3) flask_app.py <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask, render_template, request\nimport matplotlib.pyplot as plt\nfrom wordcloud import WordCloud\nimport time\n \napp = Flask(__name__)\n \n@app.route('\/wordcloud', methods=&#91;'GET','POST'])\ndef wordcloud():\n    if request.method == 'GET':\n        return render_template('wordcloud.html')\n    elif request.method == 'POST':\n        content = request.form&#91;'content']\n        font_path = '\/home\/aiclub\/mysite\/static\/NanumGothic.ttf'\n        wordcloud = WordCloud(font_path=font_path, background_color=\"white\", width=400, height=400)\n        wordcloud = wordcloud.generate(content)\n        fig = plt.figure(figsize=(6,6))\n        plt.imshow(wordcloud)\n        plt.axis('off')\n        plt.show()\n        fig.savefig('\/home\/aiclub\/mysite\/static\/wordcloud.png')\n        return render_template('wordcloud.html', content=content, time=time.time())<\/code><\/pre>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>2. \uac8c\uc2dc\ud310\uc744 \ub9cc\ub4e4 \ub54c \ud30c\uc77c \uc5c5\ub85c\ub4dc \uae30\ub2a5\uc774 \ud544\uc694\ud558\uae30\uc5d0 Flask\uc758 File\uc5c5\ub85c\ub4dc \uac1c\ub150\uc744 \uc124\uba85\ud558\uace0 \uc9c1\uc811 \uc774\ubbf8\uc9c0 \ud30c\uc77c\uc744 \uc5c5\ub85c\ub4dc\ud558\uba74 \uc0ac\uc9c4\uc774 \ub4f1\ub85d\ub418\ub3c4\ub85d \ud588\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<p>\ud14c\uc2a4\ud2b8 :\u00a0<a rel=\"noreferrer noopener\" href=\"http:\/\/aiclub.pythonanywhere.com\/upload\" target=\"_blank\">http:\/\/aiclub.pythonanywhere.com\/upload<\/a><\/p>\n\n\n\n<p> 1) \/templates\/upload.html <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{% extends \"base.html\" %}\n{% block header %}\n&lt;style>\nbody { padding:50px; }\nh1 { text-align:center; }\n&lt;\/style>\n{% endblock %}\n{% block content %}\n&lt;form action=\"\/upload\" method=\"post\" enctype=\"multipart\/form-data\">\n&lt;div class=\"form-group\">\n&lt;label for=\"email\">File :&lt;\/label>\n&lt;input type=\"file\" class=\"form-control\" name=\"file\">\n&lt;\/div>\n&lt;div class=\"form-group\">\n&lt;input type=\"submit\" class=\"btn btn-primary btn-block\">\n&lt;\/div>\n&lt;\/form>\n{% if file %}\n&lt;div class=\"form-group\">\n&lt;img src=\"\/static\/upload\/{{file}}\" class=\"img-thumbnail\" alt=\"Cinque Terre\">\n&lt;\/div>\n{% endif %}\n{% endblock %}<\/code><\/pre>\n\n\n\n<p> 2) flask_app.py <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask, render_template, request\nimport matplotlib.pyplot as plt\nfrom wordcloud import WordCloud\nimport time\nfrom werkzeug import secure_filename\n \napp = Flask(__name__)\n \n@app.route('\/upload', methods=&#91;'GET','POST'])\ndef upload():\n    if request.method == 'GET':\n        return render_template('upload.html')\n    elif request.method == 'POST':\n        f = request.files&#91;'file']\n        f.save(\"\/home\/aiclub\/mysite\/static\/upload\/\" + secure_filename(f.filename))\n        return render_template('upload.html', file=secure_filename(f.filename), time=time.time())<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>3. \ub05d\uc73c\ub85c, \uc774\ubc88\uc8fc\uc5d0 \uc9c4\ud589\ud560 \uad00\ub9ac\ud398\uc774\uc9c0 \ub85c\uadf8\uc778 \uae30\ub2a5\uc744 \uad6c\ud604\ud558\uae30 \uc704\ud574\uc11c Session \uc774\ub77c\ub294 \uac1c\ub150\uc744 \uc2a4\ud130\ub514 \ud588\uc2b5\ub2c8\ub2e4.\uc811\uc18d\uc790\uc758 \uc544\uc774\ub514\uc640 \ube44\ubc88\uc774 \uc77c\uce58\ud558\uba74 \ud2b9\uc815 \ud398\uc774\uc9c0\ub97c \uc5f4\ub78c\ud560 \uc218 \uc788\ub3c4\ub85d \ub85c\uadf8\uc778 \uc815\ubcf4\ub97c \uc720\uc9c0 \ud558\ub3c4\ub85d \ud558\uc600\ub2f5\ub2c8\ub2e4.<\/p>\n\n\n\n<p>\ud14c\uc2a4\ud2b8 : <a href=\"http:\/\/aiclub.pythonanywhere.com\/login\">http:\/\/aiclub.pythonanywhere.com\/login<\/a><\/p>\n\n\n\n<p> 1) \/templates\/login.html <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{% extends \"base.html\" %}\n{% block head %}\n&lt;style>\n    body { padding:50px; }\n&lt;\/style>\n{% endblock %}\n{% block content %}\n&lt;p class=\"display-4 text-center\">LOGIN&lt;\/p>\n&lt;form action=\"\/login\" method=\"post\">\n    &lt;div class=\"form-group\">\n        &lt;label for=\"usr\">ID :&lt;\/label>\n        &lt;input type=\"text\" class=\"form-control\" name=\"userid\">\n    &lt;\/div>\n    &lt;div class=\"form-group\">\n        &lt;label for=\"usr\">PW :&lt;\/label>\n        &lt;input type=\"password\" class=\"form-control\" name=\"userpw\">\n    &lt;\/div>\n    &lt;div class=\"form-group\">\n        &lt;button type=\"submit\" class=\"btn btn-primary btn-block\">LOGIN&lt;\/button>\n    &lt;\/div>\n    {% if msg %}\n    &lt;div class=\"form-group\">\n        &lt;div class=\"alert alert-danger\">\n            &lt;strong>{{msg}}&lt;\/strong>\n        &lt;\/div>\n    &lt;\/div>\n    {% endif %}\n&lt;\/form>\n{% endblock %}<\/code><\/pre>\n\n\n\n<p> 2) \/templates\/main.html <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{% extends \"base.html\" %}\n{% block content %}\n&lt;h1 class=\"display-3 text-center\">MAIN&lt;\/h1>\n&lt;h3>\ub85c\uadf8\uc778 \uc131\uacf5&lt;\/h3>\n&lt;a href=\"\/logout\" class=\"btn btn-primary btn-block\">LGOOUT&lt;\/a>\n{% endblock %}<\/code><\/pre>\n\n\n\n<p> 3)\u00a0 flask_app.py <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask, render_template, request, redirect, session\nimport matplotlib.pyplot as plt\nfrom wordcloud import WordCloud\nimport time\nfrom werkzeug import secure_filename\n \napp = Flask(__name__)\napp.secret_key = \"apptools\"\nsession&#91;'ss_id'] = False\n \n@app.route('\/login', methods=&#91;'GET','POST'])\ndef login():\n    if request.method == 'GET':\n        return render_template('login.html')\n    elif request.method == 'POST':\n        userid = request.form&#91;'userid']\n        userpw = request.form&#91;'userpw']\n        if userid == \"admin\" and userpw == \"1234\":\n            session&#91;'ss_id'] = userid\n            return redirect('\/main')\n        else:\n            return render_template('login.html', msg=\"login Fail\")\n \n@app.route('\/main')\ndef main():\n    if session&#91;'ss_id'] == False:\n        return redirect('\/logout')\n    else:\n        return render_template('main.html')\n \n@app.route('\/logout')\ndef logout():\n    session&#91;'ss_id'] = False\n    return redirect(\"\/login\")<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1312\" height=\"640\" src=\"https:\/\/i0.wp.com\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84394204_2867304339998102_3757996135168344064_o.jpg?fit=755%2C368\" alt=\"\" class=\"wp-image-1029\" srcset=\"https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84394204_2867304339998102_3757996135168344064_o.jpg 1312w, https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84394204_2867304339998102_3757996135168344064_o-300x146.jpg 300w, https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84394204_2867304339998102_3757996135168344064_o-755x368.jpg 755w, https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84394204_2867304339998102_3757996135168344064_o-768x375.jpg 768w\" sizes=\"(max-width: 1312px) 100vw, 1312px\" \/><\/figure>\n\n\n\n<p>\uc624\ub298\uc740 \uac01\uc790\uac00 \uac00\uc838\uc628 \uac04\uc2dd\uc744 \ud568\uaed8 \ub098\ub220 \uba39\uace0\u00a0\uc190 \uc18c\ub3c5\uc57d\ub3c4 \ud558\ub098\uc529 \ub098\ub220 \uc92c\ub2f5\ub2c8\ub2e4.\ubaa8\ub450 \ucf54\ub85c\ub098 \ubc14\uc774\ub7ec\uc2a4 \uc870\uc2ec\ud558\uc2dc\uace0 \uac74\uac15\uad00\ub9ac \uc798 \ud558\uc2dc\uae30 \ubc14\ub78d\ub2c8\ub2e4.\uc774\ubc88\uc8fc\ub3c4 \uc5f4\uacf5\ubaa8\ub4dc~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>AI\ud074\ub7fd(http:\/\/aiclub.kr) 5\uc8fc\ucc28 \ubcf4\ucda9 \uc2a4\ud130\ub514\ub97c 2020\ub1442\uc6d412\uc77c \uc218\uc694\uc77c \uc800\ub141 7\uc2dc\ubd80\ud130 10\uc2dc\uae4c\uc9c0 3\uc2dc\uac04 \ubaa8\ub77c\uc5d0\uc11c \uc9c4\ud589 \ud558\uc600\uc2b5\ub2c8\ub2e4.\uc774\ubc88\uc8fc\ub294 \uba3c\uc800 \uac00\ubccd\uac8c \ud15c\ud50c\ub9bf \uac1c\ub150\uc744 \ub2e4\uc2dc\ud55c\ubc88<\/p>\n","protected":false},"author":1,"featured_media":1027,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[36,91,123,38,93,40,41],"class_list":["post-1026","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-study","tag-ai","tag-flask","tag-123","tag-38","tag-93","tag-40","tag-41"],"featured_image_urls":{"full":["https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84169130_2867304099998126_1009589254709313536_o.jpg",1312,640,false],"thumbnail":["https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84169130_2867304099998126_1009589254709313536_o-150x150.jpg",150,150,true],"medium":["https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84169130_2867304099998126_1009589254709313536_o-300x146.jpg",300,146,true],"medium_large":["https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84169130_2867304099998126_1009589254709313536_o-768x375.jpg",640,313,true],"large":["https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84169130_2867304099998126_1009589254709313536_o-755x368.jpg",640,312,true],"1536x1536":["https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84169130_2867304099998126_1009589254709313536_o.jpg",1312,640,false],"2048x2048":["https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84169130_2867304099998126_1009589254709313536_o.jpg",1312,640,false],"morenews-large":["https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84169130_2867304099998126_1009589254709313536_o.jpg",825,402,false],"morenews-medium":["https:\/\/aiclub.kr\/wp-content\/uploads\/2020\/02\/84169130_2867304099998126_1009589254709313536_o.jpg",590,288,false]},"author_info":{"info":["\uc774\uacbd\uc6a9"]},"category_info":"<a href=\"https:\/\/aiclub.kr\/?cat=32\" rel=\"category\">STUDY<\/a>","tag_info":"STUDY","comment_count":"0","_links":{"self":[{"href":"https:\/\/aiclub.kr\/index.php?rest_route=\/wp\/v2\/posts\/1026","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiclub.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiclub.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiclub.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aiclub.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1026"}],"version-history":[{"count":2,"href":"https:\/\/aiclub.kr\/index.php?rest_route=\/wp\/v2\/posts\/1026\/revisions"}],"predecessor-version":[{"id":1032,"href":"https:\/\/aiclub.kr\/index.php?rest_route=\/wp\/v2\/posts\/1026\/revisions\/1032"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aiclub.kr\/index.php?rest_route=\/wp\/v2\/media\/1027"}],"wp:attachment":[{"href":"https:\/\/aiclub.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiclub.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiclub.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}