模拟政务服务问答系统开发,web前端开发,后端接受请求回答用户问题,通过API接口输送数据。

web前端页面设计

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>政务服务问答系统</title>
<style>
body {
    font-family: 'Arial', sans-serif;
    background-color: #8b9be2;
    margin: 0;
    padding: 0;
}
#header {
    background-color: #2513b0;
    color: white;
    padding: 10px 20px;
    text-align: center;
}
#navigation {
    background-color: #2012b8;
    overflow: hidden;
}
#navigation ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
}
#navigation ul li {
    float: left;
}
#navigation ul li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}
#navigation ul li a:hover {
    background-color: #ddd;
    color: black;
}
#content {
    background-color: white;
    padding: 20px;
    margin: 10px;
    border-radius: 5px;
    box-shadow: 0px 0px 10px #888;
}
#userInput {
    width: 100%;
    padding: 12px 20px;
    margin: 8px 0;
    box-sizing: border-box;
    border: 2px solid #120c0c;
    border-radius: 4px;
}
button {
    background-color: #1815bc;
    color: white;
    padding: 14px 20px;
    margin: 8px 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
button:hover {
    background-color: #1824c4;
}
#result {
    background-color: #e3e2e7;
    padding: 10px;
    margin-top: 10px;
}
</style>
</head>
<body>

<div id="header">
    <h1>政务服务问答系统</h1>
</div>

<div id="navigation">
    <ul>
        <li><a href="#">首页</a></li>
        <li><a href="#">查询</a></li>
        <li><a href="#">搜索</a></li>
        <li><a href="#">资讯</a></li>
    </ul>
</div>

<div id="content">
    <input type="text" id="userInput" placeholder="请输入您的问题">
    <button onclick="sendQuery()">搜索</button>
    <p id="result"></p>
</div>

<script>
function sendQuery() {
    var userInput = document.getElementById('userInput').value;

    fetch('http://127.0.0.1:5000/api/predict', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({input: userInput})
    })
    .then(response => {
        if (!response.ok) {
            throw new Error('Network response was not ok');
        }
        return response.json();
    })
    .then(data => {
        document.getElementById('result').innerHTML = data.prediction;
    })
    .catch(error => {
        console.error('There was a problem with the fetch operation:', error);
    });
}
</script>

</body>
</html>

后端接受请求,回答问题

from flask import Flask, request, jsonify
from flask_cors import CORS

app = Flask(__name__)
CORS(app)

@app.route('/api/predict', methods=['POST'])
def predict():
    user_input = request.json.get('input')
    
    # 根据输入问题类型返回不同的预测结果
    if "政务服务" in user_input:
        prediction = "这是全新的政务服务系统,有什么需要帮助的"
    elif "天气预报" in user_input:
        prediction = "明天的天气将会是晴朗的"
    elif "经济发展" in user_input:
        prediction = "我国的经济发展将继续保持稳定增长"
    elif "梁正涛是谁" in user_input:
        prediction = "他是个人,贵州大学学生"
    else:
        prediction = "对不起,我没有理解您的问题,请您重新提问。"
    
    return jsonify({'prediction': prediction})

if __name__ == '__main__':
    app.run()

注意安装必要的库

安装方法:

win+R,cmd

  • 28
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值