[Python] make colorfull checkmarks using input comment

Discussão em 'Python' iniciado por Stack, Maio 1, 2025.

  1. Stack

    Stack Membro Participativo

    i would like to make web page looks like this :let us check following image [​IMG]

    let us suppose that user enters positive comment, than we should have green check mark, otherwise red check mark :here is my python code :

    from flask import Flask,request,render_template
    from nltk.sentiment.vader import SentimentIntensityAnalyzer
    model =SentimentIntensityAnalyzer()
    app =Flask(__name__)
    @app.route('/')
    def hello_comment():
    return render_template('Select_comment.html')

    @app.route('/',methods=['POST','GET'])
    def read_comment():
    comment =request.form['mycomment']

    polarity_scores =model.polarity_scores(comment)
    if polarity_scores['pos']>0.5:
    text ='positive'
    else:
    text ='not positive'
    return render_template('Select_comment.html',name=text)


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


    and correspondng html file :

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Select comment</title>
    </head>
    <body>
    <h1> Write your comment here </h1>

    <form action="/" method="post">
    <input type="text" name="mycomment" id="comment">
    <input type="submit" value="read_comment">
    </form>
    <p> your comment is {{ name }} </p>
    </body>
    </html>


    now result of this is : [​IMG]

    i need something like this, how can i make it ? thanks in advance

    Continue reading...

Compartilhe esta Página