Skip to content

Commit

Permalink
modify apis.md document, and add a web to api test (deepwel#23)
Browse files Browse the repository at this point in the history
* add the counter to make the index page can work

* 1. add web-util.thml so the user can use the web to test the provided api service.
2. modify the apis document add the api description,
  • Loading branch information
JiaLei123 authored and crownpku committed Nov 27, 2017
1 parent 1a012da commit 6b91b75
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 60 deletions.
21 changes: 16 additions & 5 deletions chi_annotator/webui/apis/ca.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

from flask import Flask, request, redirect, url_for, jsonify, send_from_directory
from flask_cors import CORS
from werkzeug.utils import secure_filename
import os
from utils.mongoUtil import get_mongo_client
Expand All @@ -10,6 +11,7 @@

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
CORS(app)


@app.route("/")
Expand Down Expand Up @@ -70,13 +72,19 @@ def load_local_dataset():
load local unlabeled dataset
:return:
"""
filepath = request.args.get("filepath")
if request.method == 'POST':
filepath = request.data.get("filepath")
else:
filepath = request.args.get("filepath")
print(filepath)
# read file
ca = get_mongo_client()
with open(filepath) as f:
ca = get_mongo_client(uri='mongodb://localhost:27017/')
with open(filepath, 'r', encoding='utf-8') as f:
for line in f:
# label, txt = line.split(" ", 1)
ca["test"].insert_one({"txt": line})
print("get string %s" % line)
label, txt = line.split(" ", 1)
ca["test"].insert_one({"txt": txt, "label": label})

return jsonify(data={"status": "success"}, code=200, message="load success")

Expand Down Expand Up @@ -159,4 +167,7 @@ def check_offline_progress():
ca = get_mongo_client()
text = ca["test"].insert_one({"label": label, "text": text})

return jsonify(data={"progress": 50}, code=200, message="annotate success")
return jsonify(data={"progress": 50}, code=200, message="annotate success")

if __name__=="__main__":
app.run()
3 changes: 2 additions & 1 deletion chi_annotator/webui/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ <h2>Welcome to canno chinese annotator!!</h2>
<li class="selected-item"><a href="text_classification.html">Text Classification</a></li>
<li><a href="examples.html">Named Entity Reconisition</a></li>
<li><a href="#">Information Extraction</a></li>
<li><a href="index.html">Help</a></li>
<li><a href="web_util.html">web api util</a></li>
<li><a href="index.html">Help</a></li>
</ul>
</nav>

Expand Down
46 changes: 46 additions & 0 deletions chi_annotator/webui/static/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,49 @@ var example2 = new Vue({
})



axios.defaults.baseURL = 'http://localhost:5000';
// axios.interceptors.request.use(
// config =>{
// config.data = JSON.stringify(config.data)
// config.headers = {
// 'Content-Type':'application/json'
// }
// return config;
// }
// );

var load_local_data = new Vue({
el: '#load_local_data',
data: {
message: "load local test data",
file_path: 'D:\\Github\\Chinese-Annotator\\chi_annotator\\data\\files\\spam_classify_chi_shuf.txt',
},
// define methods under the `methods` object
methods: {
load_local_data_post: function (event) {
// Make a request for a user with a given ID
axios.post('/load_local_dataset',{
filepath: this.file_path,
})
.then(function (response) {
this.message = response.data.message
console.log(response);
})
.catch(function (error) {
console.log(error);
});
},
load_local_data_get: function (event) {
// Make a request for a user with a given ID
axios.get('/load_local_dataset?filepath=' + this.file_path)
.then(function (response) {
this.message = response.data.message
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
}
})
122 changes: 68 additions & 54 deletions chi_annotator/webui/static/text_classification.html
Original file line number Diff line number Diff line change
@@ -1,74 +1,88 @@
<!doctype html>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>anatine - a free css template</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
<!--[if lt IE 9]>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>anatine - a free css template</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--
<!--
anatine, a free CSS web template by ZyPOP (zypopwebtemplates.com/)
Download: http://zypopwebtemplates.com/
License: Creative Commons Attribution
//-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
</head>

<body>

<section id="body" class="width">
<aside id="sidebar" class="column-left">
<section id="body" class="width">
<aside id="sidebar" class="column-left">

<header>
<h1><a href="#">Canno</a></h1>
<h1>
<a href="#">Canno</a>
</h1>

<h2>Welcome to canno chinese annotator!!</h2>

</header>

<nav id="mainnav">
<ul>

<li><a href="index.html">Text Classification</a></li>
<li><a href="examples.html">Named Entity Reconisition</a></li>
<li><a href="#">Information Extraction</a></li>
<li ><a href="index.html">Help</a></li>
<ul>

<li>
<a href="index.html">Text Classification</a>
</li>
<li>
<a href="examples.html">Named Entity Reconisition</a>
</li>
<li>
<a href="#">Information Extraction</a>
</li>
<li>
<a href="web_util.html">web api util</a>
</li>
<li>
<a href="index.html">Help</a>
</li>
</ul>
</nav>



</aside>
<section id="content" class="column-right">

<article class="expanded">

<h2>Text Classification</h2>
<!--<div class="article-info">Posted on <time datetime="2013-05-14">14 May</time> by <a href="#" rel="author">Joe Bloggs</a></div>-->


<!--<p>Purchasing a template license for 8.00 GBP (at time of writing around 12 USD) gives you the right to remove any branding including links, logos and source tags relating to ZyPOP. As well as waiving the attribution requirement, your payment will also help us provide continued support for users as well as creating new web templates. Find out more about how to buy at the licensing page on our website which can be accessed at <a href="http://zypopwebtemplates.com/licensing" title="template license">http://zypopwebtemplates.com/licensing</a></p>-->

<!--<br/>-->
<!--<br/>-->
<!--<br/>-->
<br/>
<h3>Labeled Text</h3>

<p>Morbi fermentum condimentum felis, commodo vestibulum sem mattis sed. <label class="labeled">Aliquam magna ante</label>, mollis vitae tincidunt in, malesuada vitae turpis. Sed aliquam libero ut velit bibendum consectetur. Quisque sagittis, est in laoreet semper, enim dui consequat felis, faucibus ornare urna velit nec leo. Maecenas condimentum velit vitae est lobortis fermentum. In tristique sem vitae metus ornare luctus tempus nisl volutpat. Integer et est id nisi tempus pharetra sagittis et libero.</p>
<!--<p>Writers From the Right and Left on Trump Jr., the Future of the F.B.I.ORG, Health Care and More</p>-->

<a href="#" class="button">right</a>
<a href="#" class="button button-reversed">wrong</a>
&nbsp;&nbsp;
<a href="#" class="button">undo</a>
<a href="#" class="button button-reversed">cancel</a>
</article>
<article class="expanded">
<h3>History</h3>
</aside>
<section id="content" class="column-right">

<article class="expanded">

<h2>Text Classification</h2>
<!--<div class="article-info">Posted on <time datetime="2013-05-14">14 May</time> by <a href="#" rel="author">Joe Bloggs</a></div>-->


<!--<p>Purchasing a template license for 8.00 GBP (at time of writing around 12 USD) gives you the right to remove any branding including links, logos and source tags relating to ZyPOP. As well as waiving the attribution requirement, your payment will also help us provide continued support for users as well as creating new web templates. Find out more about how to buy at the licensing page on our website which can be accessed at <a href="http://zypopwebtemplates.com/licensing" title="template license">http://zypopwebtemplates.com/licensing</a></p>-->

<!--<br/>-->
<!--<br/>-->
<!--<br/>-->
<br/>
<h3>Labeled Text</h3>

<p>Morbi fermentum condimentum felis, commodo vestibulum sem mattis sed.
<label class="labeled">Aliquam magna ante</label>, mollis vitae tincidunt in, malesuada vitae turpis. Sed aliquam libero ut velit bibendum
consectetur. Quisque sagittis, est in laoreet semper, enim dui consequat felis, faucibus ornare urna velit nec leo.
Maecenas condimentum velit vitae est lobortis fermentum. In tristique sem vitae metus ornare luctus tempus nisl volutpat.
Integer et est id nisi tempus pharetra sagittis et libero.</p>
<!--<p>Writers From the Right and Left on Trump Jr., the Future of the F.B.I.ORG, Health Care and More</p>-->

<a href="#" class="button">right</a>
<a href="#" class="button button-reversed">wrong</a>
&nbsp;&nbsp;
<a href="#" class="button">undo</a>
<a href="#" class="button button-reversed">cancel</a>
</article>
<article class="expanded">
<h3>History</h3>
<table>
<tr>
<th>ID</th>
Expand All @@ -95,21 +109,21 @@ <h3>History</h3>
</table>
<p>&nbsp;</p>

</article>

</article>



<footer class="clear">
<p>&copy; 2017 sitename. <a href="http://zypopwebtemplates.com/">Free CSS Templates</a> by Canno Groups</p>
<p>&copy; 2017 sitename.
<a href="http://zypopwebtemplates.com/">Free CSS Templates</a> by Canno Groups</p>
</footer>

</section>

<div class="clear"></div>

</section>


<script src="js/core.js"></script>
</body>
</html>

</html>
86 changes: 86 additions & 0 deletions chi_annotator/webui/static/web_util.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!doctype html>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>anatine - a free css template</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
</head>

<body>
<section id="body" class="width">
<aside id="sidebar" class="column-left">

<header>
<h1>
<a href="#">anatine</a>
</h1>

<h2>Welcome to canno chinese annotator!!</h2>

</header>

<nav id="mainnav">
<ul>
<li>
<a href="index.html">Home</a>
</li>
<li class="selected-item">
<a href="examples.html">Examples</a>
</li>
<li>
<a href="text_classification.html">Text Classification</a>
</li>
<li>
<a href="web_util.html">web api util</a>
</li>
</ul>
</nav>



</aside>
<section id="content" class="column-right">

<article>
<h3>API Testing</h3>

<blockquote>
<p>this web is for API testing, it list all API that provided by the web service backend. user can use this web site
to access the web api send GET or POST request</p>
</blockquote>


<h3>Load Local Data</h3>
<!--<div class="article-info">Posted on <time datetime="2013-05-14">14 May</time> by <a href="#" rel="author">Joe Bloggs</a></div>-->
<div id="load_local_data">
<label></label>
<input type="text" size="50" v-model="file_path"/>
<button class="formbutton" v-on:click="load_local_data_post">load local data by POST</button>
<button class="formbutton" v-on:click="load_local_data_get">load local data by GET</button>
<p>{{ message }}</p>
</div>


</article>


<footer class="clear">
<p>&copy; 2017 sitename.
<a href="http://zypopwebtemplates.com/">Free CSS Templates</a> by ZyPOP</p>
</footer>

</section>

<div class="clear"></div>

</section>


<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue"></script>
<script src="js/core.js"></script>
</body>

</html>
26 changes: 26 additions & 0 deletions docs/apis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#API 文档

## 如何启动web和Reset API 服务
本框架使用前后端分离,所以要分别启动前端的页面和后端的web服务

### 启动前端页面
前端使用纯前端技术,不需要后端之前就可以运行

运行方式:
1. 直接使用浏览器打开*.html
2. 使用Apache http service,使用这种方式只需要修改apache服务器的配置文件./conf/httpd.conf中的DocumentRoot和Directory,将其修改为Chinese-Annotator\chi_annotator\webui\static。然后重启httpd服务器,直接访问localhost即可

### 后端服务的启动
后端使用Python的flask,所以需要安装必要的包,所需要的依赖包参见项目目录中的requirements.txt
1. 将/webui export到PYTHONPATH
2. 运行 python ca.py


## API 接口说明
/load_local_dataset

支持post和get请求
参数:filepath 本地文件的绝对路径

功能: 将本地的文件load到Mongo数据库

0 comments on commit 6b91b75

Please sign in to comment.