app
1from flask import Flask, request, render_template, jsonify 2from asyncio import new_event_loop 3from get_tweets import get_tweet 4app = Flask(__name__, template_folder='../frontend/templates', static_folder='../frontend/static') 5from ML import NaiveBayes, NeuralNetwork 6 7@app.route('/') 8def index(): 9 """ 10 Flask route to return the main search page. 11 """ 12 return render_template('index.html') 13 14@app.route('/search') 15def search(): 16 """ 17 Search page that visualizes the sentiment data of the tweet. 18 """ 19 q = request.args.get('query') 20 loop = new_event_loop() 21 tweet = loop.run_until_complete(get_tweet(q)) 22 return render_template('search.html', tweet=tweet) 23 24@app.route('/naivebayes', methods=['GET']) 25def naivebayes(): 26 """ 27 Uses the ML NaiveBayes Module to perform sentiment analysis. 28 Args: 29 query (str) : The url of the tweet 30 Returns: 31 JSON: 'p' or 'n' value dictating sentiment. 32 """ 33 data = request.args.get('query') 34 loop = new_event_loop() 35 data = loop.run_until_complete(NaiveBayes.NaiveBayes().predict(data)) 36 return jsonify(data) 37 38@app.route('/neuralnetwork', methods=['GET']) 39def neuralnetwork(): 40 """ 41 Uses the ML Neural Netowrk Module to perform sentiment analysis. 42 Args: 43 query (str) : The url of the tweet 44 Returns: 45 JSON: 'p' or 'n' value dictating sentiment. 46 """ 47 data = request.args.get('query') 48 loop = new_event_loop() 49 data = loop.run_until_complete(NeuralNetwork.NeuralNetwork().predict(data)) 50 return jsonify(data) 51 52if __name__ == '__main__': 53 app.run(debug=True, port=5000)
app =
<Flask 'app'>
@app.route('/')
def
index():
8@app.route('/') 9def index(): 10 """ 11 Flask route to return the main search page. 12 """ 13 return render_template('index.html')
Flask route to return the main search page.
@app.route('/search')
def
search():
15@app.route('/search') 16def search(): 17 """ 18 Search page that visualizes the sentiment data of the tweet. 19 """ 20 q = request.args.get('query') 21 loop = new_event_loop() 22 tweet = loop.run_until_complete(get_tweet(q)) 23 return render_template('search.html', tweet=tweet)
Search page that visualizes the sentiment data of the tweet.
@app.route('/naivebayes', methods=['GET'])
def
naivebayes():
25@app.route('/naivebayes', methods=['GET']) 26def naivebayes(): 27 """ 28 Uses the ML NaiveBayes Module to perform sentiment analysis. 29 Args: 30 query (str) : The url of the tweet 31 Returns: 32 JSON: 'p' or 'n' value dictating sentiment. 33 """ 34 data = request.args.get('query') 35 loop = new_event_loop() 36 data = loop.run_until_complete(NaiveBayes.NaiveBayes().predict(data)) 37 return jsonify(data)
Uses the ML NaiveBayes Module to perform sentiment analysis. Args: query (str) : The url of the tweet Returns: JSON: 'p' or 'n' value dictating sentiment.
@app.route('/neuralnetwork', methods=['GET'])
def
neuralnetwork():
39@app.route('/neuralnetwork', methods=['GET']) 40def neuralnetwork(): 41 """ 42 Uses the ML Neural Netowrk Module to perform sentiment analysis. 43 Args: 44 query (str) : The url of the tweet 45 Returns: 46 JSON: 'p' or 'n' value dictating sentiment. 47 """ 48 data = request.args.get('query') 49 loop = new_event_loop() 50 data = loop.run_until_complete(NeuralNetwork.NeuralNetwork().predict(data)) 51 return jsonify(data)
Uses the ML Neural Netowrk Module to perform sentiment analysis. Args: query (str) : The url of the tweet Returns: JSON: 'p' or 'n' value dictating sentiment.