Skip to content

Commit

Permalink
add hotwords page
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasxlu committed Apr 5, 2019
1 parent 024005a commit 7d20391
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ with RESTful APIs. The platform is developed and maintained by [@LucasX](https:/
5. start django server: ```python3 manage.py runserver 0.0.0.0:8001```
6. open your browser and visit welcome page: ```http://www.lucasx.top:8001/cv/index```

![index](index.png)

## Contributor
* [@LucasX](https://github.com/lucasxlu): system/algorithm/deployment
Expand Down
4 changes: 4 additions & 0 deletions XCloud/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from django.urls import path, include

from cv import views

urlpatterns = [
path('admin/', admin.site.urls),
path('cv/', include('cv.urls')),
path('dm/', include('dm.urls')),
path('nlp/', include('nlp.urls')),
url('index', views.index, name='index'),
]
14 changes: 7 additions & 7 deletions cv/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ <h4>
<strong>Computer Vision</strong>
</h4>
<p>Face Analysis</p>
<a href="mcloud" class="btn btn-light" target="_blank">Know
<a href="/cv/mcloud" class="btn btn-light" target="_blank">Know
More</a>
</div>
</div>
Expand Down Expand Up @@ -150,39 +150,39 @@ <h2>Research Achievements</h2>
<div class="row">
<div class="col-md-6">
<div class="portfolio-item">
<a href="nsfwview" target="_blank">
<a href="/cv/nsfwview" target="_blank">
<img class="img-portfolio img-responsive"
src="/static/img/portfolio-1.png">
</a>
</div>
</div>
<div class="col-md-6">
<div class="portfolio-item">
<a href="plantview">
<a href="/cv/plantview" target="_blank">
<img class="img-portfolio img-responsive"
src="/static/img/portfolio-2.png"/>
</a>
</div>
</div>
<div class="col-md-6">
<div class="portfolio-item">
<a href="mcloud" target="_blank">
<a href="/cv/mcloud" target="_blank">
<img class="img-portfolio img-responsive"
src="/static/img/portfolio-3.png">
</a>
</div>
</div>
<div class="col-md-6">
<div class="portfolio-item">
<a href="fbpview" target="_blank">
<a href="/cv/fbpview" target="_blank">
<img class="img-portfolio img-responsive"
src="/static/img/portfolio-4.png">
</a>
</div>
</div>
<div class="col-md-6">
<div class="portfolio-item">
<a href="pdrview" target="_blank">
<a href="/cv/pdrview" target="_blank">
<img class="img-portfolio img-responsive"
src="/static/img/portfolio-5.png">
</a>
Expand Down Expand Up @@ -258,7 +258,7 @@ <h4><strong>XCloud</strong>
</li>
</ul>
<hr class="small">
<p class="text-muted">Copyright &copy; 2018. LucasX All
<p class="text-muted">Copyright &copy; 2019. LucasX All
rights reserved.</p>
</div>
</div>
Expand Down
Binary file added index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions nlp/templates/hotwords.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Government Report</title>
<script src="/static/js/jquery-3.1.1.min.js"></script>
<script src="/static/js/echarts.js"></script>
<script src="/static/js/echarts-wordcloud.js"></script>
<script src="/static/js/common.js"></script>
<script src="/static/js/layer/layer.js"></script>
<link rel="stylesheet" href="/static/bootstrap-4.0.0-alpha.5-dist/css/bootstrap.min.css">
<link rel="icon" type="image/png" sizes="192x192" href="/static/favicon.ico">
<link rel="stylesheet" href="/static/css/common.css">
<link rel="stylesheet" href="/static/css/font-awesome.min.css">
<style>
textarea {
width: 100%;
padding: 15px;
display: block;
margin: 20px auto;
}

h2 {
font-family: Times, serif;
}
</style>
</head>
<body>

<div class="container">
<h2 style="padding-top: 20px;">Hot Words Analysis</h2>
<textarea name="text" rows="10"></textarea>
<button class="btn btn-primary btn-block" onclick="showKeywords()"><i class="fa fa-calculator"
aria-hidden="true"></i>TF-IDF
</button>
<div id="keywords" style="width: 100%; height:600px;"></div>
</div>

<script type="text/javascript">

function showKeywords() {
var index = layer.load(0, {shade: false});
var urlPrefix = "/nlp/hotwords";
var myChart = echarts.init(document.getElementById('keywords'));

var wordcloud = [];
$.ajax({
url: urlPrefix,
data: {"sentence": $("textarea").val().trim()},
dataType: "json",
type: "GET"
}).done(function (data) {
console.log(data);

for (var i = 0; i < data.data.length; i++) {
var item = data.data[i];
var keywordsObj = new Object();
keywordsObj['name'] = item[0];
keywordsObj['value'] = item[1];
wordcloud.push(keywordsObj);
}
layer.close(index);

var option = {
tooltip: {},
series: [{
type: 'wordCloud',
gridSize: 2,
sizeRange: [25, 60],
rotationRange: [-90, 90],
shape: 'pentagon',
width: 900,
height: 600,
textStyle: {
normal: {
color: function () {
return 'rgb(' + [
Math.round(Math.random() * 160),
Math.round(Math.random() * 160),
Math.round(Math.random() * 160)
].join(',') + ')';
}
},
emphasis: {
shadowBlur: 10,
shadowColor: '#333'
}
},
data: wordcloud
}]
};
myChart.setOption(option);
});
}
</script>

<div align="center">
<div class="amz-toolbar" id="amz-toolbar" style="right: 10px;">
<a title="Back to Top" class="am-icon-btn am-active" id="amz-go-top"><i class="fa fa-arrow-up"></i></a>
<a href="/cv/index" title="Back to Home" class="am-icon-btn am-icon-faq am-icon-question-circle"><i
class="fa fa-home"></i></a>
</div>
<footer>Copyright &copy; 2019 <a href="/cv/index" style="text-decoration: none">XCloud</a></footer>
</div>

<link rel="stylesheet" href="/static/css/index.css">
<link rel="stylesheet" href="/static/css/common.css">
</body>
</html>
2 changes: 2 additions & 0 deletions nlp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
urlpatterns = [
path('welcome', views.welcome, name='welcome'),
url('wordseg', views.word_seg, name='wordseg'),
url('hotwordsview', views.hotwords_view, name='hotwordsview'),
url('hotwords', views.hotwords, name='hotwords'),
url('sentimentview', views.sentiment_view, name='sentimentview'),
url('sentiment', views.sentiment, name='sentiment'),
]
39 changes: 37 additions & 2 deletions nlp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
from collections import OrderedDict

import jieba as jieba
import jieba
import jieba.analyse
from django.http import HttpResponse
from django.shortcuts import render
Expand Down Expand Up @@ -55,7 +55,7 @@ def word_seg(request):

result['data'] = {
'words': seg_words,
'tf-idf': tfidf
'tfidf': tfidf
}

json_result = json.dumps(result, ensure_ascii=False)
Expand Down Expand Up @@ -110,3 +110,38 @@ def sentiment(request):

def sentiment_view(request):
return render(request, 'sentiment.html')


def hotwords(request):
"""
calculation for wordcloud
@Note: currently supported by jieba, but will be replaced customized model in the near future!
:param request:
:return:
"""
sentence = request.GET.get('sentence')
result = OrderedDict()

tik = time.time()

if sentence is None:
result['code'] = 1
result['msg'] = 'Invalid Sentence Input'
result['data'] = None
else:
result['code'] = 0
result['msg'] = 'success'

words_and_weights = jieba.analyse.textrank(sentence, topK=30, withWeight=True)

result['data'] = words_and_weights

result['elapse'] = time.time() - tik

json_result = json.dumps(result, ensure_ascii=False)

return HttpResponse(json_result)


def hotwords_view(request):
return render(request, 'hotwords.html')

0 comments on commit 7d20391

Please sign in to comment.