| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
|
|
| import pickle |
| from flask import Flask, request, render_template |
| from flask_bootstrap import Bootstrap |
| import app_utilities |
|
|
| |
| |
| app = Flask(__name__) |
| Bootstrap(app) |
|
|
| @app.route('/') |
| def index(): |
| """Renders the landing page for tweet input.""" |
| return render_template('index.html') |
|
|
| @app.route('/predict', methods=['POST']) |
| def predict(): |
| """ |
| Handles the form submission and displays the prediction result. |
| |
| Returns: |
| Rendered result HTML with the model's prediction outcome. |
| """ |
| if request.method == 'POST': |
| |
| tweet = request.form["tweet"] |
| input_data = [tweet] |
| |
| |
| |
| my_prediction = app_utilities.tweet_prediction(str(input_data)) |
| |
| return render_template("result.html", prediction=my_prediction, name=tweet) |
|
|
| @app.errorhandler(404) |
| def page_not_found(e): |
| """ |
| Custom 404 error handler. |
| Renders the personalized 404 page when a resource is not found. |
| """ |
| return render_template('404.html'), 404 |
|
|
| |
| if __name__ == '__main__': |
| |
| app.run(host='0.0.0.0', port=7860) |
|
|