我有以下html
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sell Weapons</title>
</head>
<body>
<form action="{{ url_for('predict')}}"method="post">
<label for="comment1">evaluate first product</label><br>
<input type="text" id="comment1" name="comment" required="required"><br>
<label for="comment2">evaluate second product</label><br>
<input type="text" id="comment2" name="comment" required="required"><br>
<label for="comment">evaluate third product</label><br>
<input type="text" id="comment" name="comment" required="required"><br>
<input type="submit" value="Submit">
</form>
<h4 style="color:Violet;">
{{ prediction_text }} </h4>
</body>
</html>
when we run it, I get following output :
在这个表单中,我写了三个文本,但它只显示了一个,这里是对应的Python代码,
import numpy as np
from flask import Flask,request,jsonify,render_template
import pickle
from transformers import pipeline
app = Flask(__name__)
@app.route('/')
def home():
return render_template("Commenting.html")
@app.route('/predict',methods=['POST'])
def predict():
text = [x for x in request.form.values()]
# text=list(text)
return render_template('Commenting.html', prediction_text=text)
# sentiment_pipeline = pipeline("sentiment-analysis")
# result =sentiment_pipeline(text)[0]
# if result['label']=='POSITIVE':
# return render_template('Commenting.html',prediction_text=f'emotion of comment is positive')
# else:
# return render_template('Commenting.html', prediction_text=f'emotion of comment is not positive')
if __name__ =="__main__":
app.run()
你能告诉我为什么我只能访问第一个文本吗?其他人呢?