| from flask import Flask, jsonify, render_template, request, make_response |
| import transformers |
| import torch |
| from torch import nn |
| import re |
| import numpy as np |
| import pandas as pd |
| from collections import OrderedDict |
| |
| |
|
|
| app = Flask(__name__) |
|
|
| |
| dictOfModels = {"BERT" : transformers.pipeline('sentiment-analysis', model="nlptown/bert-base-multilingual-uncased-sentiment")} |
| |
| listOfKeys = [] |
| for key in dictOfModels : |
| listOfKeys.append(key) |
|
|
| def get_prediction(message,model): |
| |
| results = model(message) |
| return results |
|
|
| @app.route('/', methods=['GET']) |
| def get(): |
| |
| return render_template("home.html", len = len(listOfKeys), listOfKeys = listOfKeys) |
|
|
| @app.route('/', methods=['POST']) |
| def predict(): |
| message = "This is good movies" |
| |
| results = get_prediction(message, dictOfModels['BERT']) |
| print(f'User selected model : {request.form.get("model_choice")}') |
| my_prediction = f'The feeling of this text is {results[0]["label"]} with probability of {results[0]["score"]*100}%.' |
| return render_template('result.html', text = f'{message}', prediction = my_prediction) |
|
|
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |