I put pandas, plotly, and MeCab in flask, launched a simple web application on Heroku, and tried to enable simple morphological analysis and aggregation from anywhere.
I was addicted to deploying Heroku, so don't forget to record it.
Windows10 Python3.7 Anaconda
Flask preparation omitted. No problem locally.
main.py test code (xlsx input, plotly output, html output part is deleted.)
# -*- coding: utf-8 -*-
import os
import csv
from flask import *
from werkzeug.utils import secure_filename
import pandas as pd
import plotly
import pathlib
import MeCab
app = Flask(__name__)
@app.route("/")
def init():
cmd = "pip freeze"
out = os.popen(cmd).read()
return out
@app.route("/0")
def mecab():
sentence = """Amazon Elastic Compute Cloud for AWS's Famous Services(EC2)And Amazon Simple Storage Service(S3)There is.
Compared to the physical server farms owned by clients so far, AWS has the advantage of being able to quickly provide large-scale computing power."""
t = MeCab.Tagger('')
out = t.parse(sentence)
return out
if __name__ == '__main__':
app.run()
requirements.txt
gunicorn==19.9.0
click==7.1.1
Flask==1.1.2
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
numpy==1.18.3
pandas==1.0.3
plotly==4.6.0
python-dateutil==2.8.1
pytz==2019.3
retrying==1.3.3
six==1.14.0
Werkzeug==1.0.1
xlrd==1.2.0
mecab-python3
Procfile
web: gunicorn main:app
.buildpacks
https://github.com/sunny4381/heroku-buildpack-linuxbrew.git
.cellar
mecab
mecab-ipadic
$ git init
$ heroku create flask-mecab-heroku
$ heroku create --buildpack https://github.com/heroku/heroku-buildpack-multi
$ heroku config:add LD_LIBRARY_PATH=/app/.linuxbrew/lib
$ heroku config:set MECAB_PATH=/app/.linuxbrew/lib/libmecab.so
$ git add .
$ git commit -m "first"
$ git push heroku master
reference python + django + scikit-learn + mecab (1) on heroku https://qiita.com/kenchin110100/items/6f1c84ac8858525fffc5
I can install mecab with Linuxbrew, but pip doesn't work. I can install packages with pip, but Linuxbrew doesn't work.
$ heroku create --buildpack https://github.com/heroku/heroku-buildpack-multi Doesn't work. I had to set multiple buildpacks.
$ git init
$ heroku create flask-mecab-heroku2
$ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-multi.git
$ heroku buildpacks:add --index 2 heroku/python
$ heroku config:add LD_LIBRARY_PATH=/app/.linuxbrew/lib
$ heroku config:set MECAB_PATH=/app/.linuxbrew/lib/libmecab.so
$ git add .
$ git commit -m "first"
$ git push heroku master
output https://flask-mecab-heroku2.herokuapp.com/ https://flask-mecab-heroku2.herokuapp.com/0
Good grief. Now you can create an analysis page.
Looking back, it's a simple thing, but when you don't understand, you don't understand. Also, it seems that this is not the optimal solution ...
It would be nice to be able to create a web app around here, but heroku has only about 500MB of memory. https://qiita.com/kzuzuo/items/d41327433c9cdc6a5fd3 https://qiita.com/kzuzuo/items/8a80d8974bf3a7db7e54
Recommended Posts