怎么将返回的prediction,在文本框的网页中显示
from flask import Flask, render_template, request
import pickle
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def home():
if request.method == 'POST':
# 从表单中获取用户输入的文本
title = request.form['title']
x = int(str(torch.argmax(model(word2vec(title))))[-2])
x = str(x)
print(x)
# 将预测结果作为参数传递给结果页面,并显示结果
# return render_template('index.html', prediction=x, description=description)
return render_template('index.html', prediction=x, description=x)
# 显示包含title的文本框和提交按钮的表单页面
return '''
<!DOCTYPE html>
<html>
<head>
<title>My Awesome Webpage</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
form {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
</style>
</head>
<body>
<div>
<form>
<label for="title">请输入待检测文本:</label>
<br>
<textarea id="title" name="title" required style="width: 600px; height: 200px;"></textarea>
<br>
<br> <!-- 添加一个换行符 -->
<label for="description">检测结果为:</label>
<br>
<input type="text" id="description" name="description" value={{ prediction }}>
<br>
<input type="submit" value="Submit">
</form>
</div>
</body>
</html>
'''
if __name__ == '__main__':
app.run()