I am really new to this python website thing. I have a VaderSentiment code that returns if a string input was positive, negative, or neutral. The code looks like this :
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
# function to print sentiments
# of the sentence.
def sentiment_scores(sentence):
# Create a SentimentIntensityAnalyzer object.
sid_obj = SentimentIntensityAnalyzer()
# polarity_scores method of SentimentIntensityAnalyzer
# object gives a sentiment dictionary.
# which contains pos, neg, neu, and compound scores.
sentiment_dict = sid_obj.polarity_scores(sentence)
print("Overall sentiment dictionary is : ", sentiment_dict)
print("sentence was rated as ", sentiment_dict['neg']*100, "% Negative")
print("sentence was rated as ", sentiment_dict['neu']*100, "% Neutral")
print("sentence was rated as ", sentiment_dict['pos']*100, "% Positive")
print("Sentence Overall Rated As", end = " ")
# decide sentiment as positive, negative and neutral
if sentiment_dict['compound'] >= 0.05 :
print("Positive")
elif sentiment_dict['compound'] <= - 0.05 :
print("Negative")
else :
print("Neutral")
# Driver code
if __name__ == "__main__" :
print("\n1st statement :")
sentence = input("Please enter a string:\n")
# function calling
sentiment_scores(sentence)
sentence = input("Please enter a second string:\n")
# function calling
sentiment_scores(sentence)
sentence = input("Please enter a third string:\n")
# function calling
sentiment_scores(sentence)
def fonction():
return 0
I also have another page that runs this script :
from flask import Flask, render_template
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import main
app = Flask(__name__)
@app.route("/",methods=['GET'])
def code():
out = open(r'main.py', 'r').read()
return exec(out)
if __name__ == '__main__':
app.run(debug=True)
When I execute the code (flask), it starts a webpage that keeps loading, and the input is displayed in my IDE instead of the webpage.
I wish to print on the webpage inputs as well as results.
Any help would be greatly appreciated :) Thanks in advance for your help.