添加前端
This commit is contained in:
parent
fa27e4bd51
commit
8ebf71cc3f
10
main.py
10
main.py
|
@ -4,7 +4,7 @@ import pandas as pd
|
|||
import re
|
||||
import math
|
||||
import json
|
||||
from flask import Flask, jsonify, request
|
||||
from flask import Flask, jsonify, request, render_template
|
||||
from flask_cors import CORS
|
||||
from pypinyin import pinyin, lazy_pinyin, Style
|
||||
|
||||
|
@ -172,10 +172,10 @@ def filter_logic(mode, parameter):
|
|||
return None, None
|
||||
|
||||
def filter_group_model2(parameter, group, hits, tones, tone_hits, word_hits):
|
||||
group = filter_with_target_field(group, 'word', parameter, word_hits)
|
||||
group = filter_with_target_field(group, 'pinyin_tone', tones, tone_hits)
|
||||
if len(group) <= 1:
|
||||
return group
|
||||
group = filter_with_target_field(group, 'pinyin_tone', tones, tone_hits)
|
||||
group = filter_with_target_field(group, 'word', parameter, word_hits)
|
||||
if len(group) <= 1:
|
||||
return group
|
||||
group['pinyin_0' ] = group.apply(lambda x: ','.join(list(lazy_pinyin(x['word'], style=Style.INITIALS, strict=False))), axis=1)
|
||||
|
@ -267,6 +267,10 @@ def predict():
|
|||
result = get_max_group(all_idiom, group, 3)
|
||||
return jsonify({'status': 0, 'message': 'success', 'result': result})
|
||||
|
||||
@app.route('/', methods=['GET'])
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
if __name__ == '__main__':
|
||||
current_work_dir = os.path.dirname(__file__)
|
||||
os.chdir(current_work_dir)
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
<html>
|
||||
|
||||
<head>
|
||||
<title>Chinese Wordle Tools</title>
|
||||
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
|
||||
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<form id="para" class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">模式</label>
|
||||
<div class="col-sm-8">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="mode" value="0" checked> 0
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="mode" value="1"> 1
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="mode" value="2"> 2
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="mode" value="3"> 3
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="parameter" class="col-sm-2 control-label">参数</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" id="parameter" name="parameter" class="form-control" placeholder="4234">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="result" class="col-sm-2 control-label">结果</label>
|
||||
<div class="col-sm-8">
|
||||
<textarea id="result" class="form-control" rows="6" readonly></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-8">
|
||||
<button id="submit" type="button" class="btn btn-default">提交</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('input[name=mode]').on('click', function (e) {
|
||||
switch ($(e.currentTarget).val()) {
|
||||
case '0':
|
||||
$("#parameter").attr('placeholder', '4324')
|
||||
break
|
||||
case '1':
|
||||
$("#parameter").attr('placeholder', 'bai tou er xin,012 010 10 001')
|
||||
break
|
||||
case '2':
|
||||
$("#parameter").attr('placeholder', '2134')
|
||||
break
|
||||
case '3':
|
||||
$("#parameter").attr('placeholder', '各执一词 4212,00 11 12 22 0010 1022')
|
||||
break
|
||||
}
|
||||
$("#parameter").val('')
|
||||
})
|
||||
$('#submit').on('click', function () {
|
||||
$.get('/predict', { mode: $("input[name='mode'][checked]").val(), parameter: $('#parameter').val() }, function (result) {
|
||||
if(result && result.status === 0){
|
||||
text = result.result.map(function(item){
|
||||
return item.word + '\t' + item.pinyin
|
||||
}).join('\n')
|
||||
$('#result').val(text)
|
||||
}
|
||||
else {
|
||||
$('#result').val(result)
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue