Skip to content

Commit

Permalink
🚀v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bighuang624 committed Apr 7, 2018
1 parent edf02c6 commit 8f739f7
Show file tree
Hide file tree
Showing 25 changed files with 30,173 additions and 123 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ ENV/

# mypy
.mypy_cache/

.DS_Store
node_modules/
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
[![Python](https://img.shields.io/badge/python-3.5%2B-green.svg)]()
[![MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/bighuang624/sentiment-analysis-webapp/blob/master/LICENSE)

情感分析 web 应用 | A web app about sentiment analysis
中文短文本情感分析 web 应用 | A web app about Chinese sentences sentiment analysis

![example.png](https://raw.githubusercontent.com/bighuang624/sentiment-analysis-webapp/master/docs/example.png)

## Installation

Expand Down Expand Up @@ -39,23 +41,26 @@ Open index.html and have fun. :smiley:

## Structure

```py
```
.
├── LICENSE
├── README.md
├── app.py
├── index.html
├── models # 存放持久化模型
├── models
│   ├── douban_comment.pkl
│   └── restaurant_comment.pkl
├── requirements.txt
├── static
│   ├── main.css
│   └── main.js
└── training # 存放模型训练代码
── training
── douban-comment.csv
├── douban_comment_trainning.py
├── restaurant-comment.csv
└── restaurant_comment_trainning.py
```

The source code of the frontend can be found in [sentiment-analysis-webapp-frontend](https://github.com/bighuang624/sentiment-analysis-webapp-frontend), which is powered by Vue.js.

## Contributors

This work is doing by Siteng Huang, Muzhe Zhou, Ziyi Wu, Zhongchao Cai, Xu Zheng and Suyang Hu.
Expand Down
19 changes: 17 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@
from flask_restful import Resource, Api, abort, reqparse
from flask_cors import CORS
from snownlp import SnowNLP
from sklearn.externals import joblib
import pandas as pd
import numpy as np

app = Flask(__name__)
cors = CORS(app, resources={r"/predict": {"origins": "*"}})
api = Api(app)

# 读取模型
restaurant_clf = joblib.load('./models/restaurant_comment.pkl')
douban_clf = joblib.load('./models/douban_comment.pkl')

# 参数解析
parser = reqparse.RequestParser()
parser.add_argument('sentence', type=str)
parser.add_argument('type', type=str)

class Prediction(Resource):
def post(self):
args = parser.parse_args()
s = SnowNLP(args['sentence'])
return s.sentiments*5, 200
if args['type'] == 'restaurant':
result = restaurant_clf.predict([args['sentence']]).astype(np.str)
return result[0], 200
elif args['type'] == 'douban':
result = douban_clf.predict([args['sentence']]).astype(np.str)
return result[0], 200
else:
s = SnowNLP(args['sentence'])
return s.sentiments*5, 200

api.add_resource(Prediction, '/predict')

Expand Down
Binary file added example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 1 addition & 33 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,33 +1 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>中文短文本情感分析</title>
<meta name="description" content="中文短文本情感分析,以 web app 的形式展示。欢迎使用!">
<meta name="keywords" content="情感分析,短文本,中文,sentiment-analysis">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./static/main.css">
</head>

<body>
<header>中文短文本情感分析</header>
<div class="container">
<input type="text" placeholder="请输入短文本">
<button id="start">开始预测</button>
<button id="random">随便测测</button>
<div class="result">
<span>情感指数:</span>
<span id="score"></span>
</div>
</div>
<footer>
<a href="https://github.com/bighuang624/sentiment-analysis-webapp" target="_blank">开源项目地址</a>
</footer>
</body>

</html>

<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="./static/main.js"></script>
<!DOCTYPE html><html><head><meta charset=UTF-8><title>中文短文本情感分析</title><meta name=description content="中文短文本情感分析项目,以 web app 的形式展示。欢迎使用!"><meta name=keywords content=情感分析,短文本,中文,sentiment-analysis><meta name=viewport content="width=device-width,initial-scale=1"><meta http-equiv=X-UA-Compatible content="ie=edge"><link rel="shortcut icon" href=./favicon.ico><link href=./static/css/app.972711d2bd911132aa864d9387b74d24.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=./static/js/manifest.3ad1d5771e9b13dbdad2.js></script><script type=text/javascript src=./static/js/vendor.9429d43577f10c9ec8f3.js></script><script type=text/javascript src=./static/js/app.5cf95aae75260ea1d81f.js></script></body></html>
Binary file removed models/.DS_Store
Binary file not shown.
Binary file added models/douban_comment.pkl
Binary file not shown.
2 changes: 2 additions & 0 deletions static/css/app.972711d2bd911132aa864d9387b74d24.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions static/css/app.972711d2bd911132aa864d9387b74d24.css.map

Large diffs are not rendered by default.

Binary file added static/fonts/ionicons.05acfdb.woff
Binary file not shown.
Binary file added static/fonts/ionicons.24712f6.ttf
Binary file not shown.
Binary file added static/fonts/ionicons.2c2ae06.eot
Binary file not shown.
Loading

0 comments on commit 8f739f7

Please sign in to comment.