import os from flask import send_from_directory from flask import Flask, render_template, request from transformers import TextClassificationPipeline, AutoTokenizer, AutoModelForSequenceClassification from transformers import logging logging.set_verbosity_error() name = 'ZoDiUOA/C19FND' tokenizer = AutoTokenizer.from_pretrained(name) model = AutoModelForSequenceClassification.from_pretrained(name, max_position_embeddings=512) model.save_pretrained("here") AutoModelForSequenceClassification.from_pretrained("here") pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer) application = app = Flask(__name__) @application.route('/favicon.ico') def favicon(): return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/vnd.microsoft.icon') @application.route('/') def home(): return render_template('home.html') @application.route('/predict', methods=['POST']) def predict(): if request.method == 'POST': input_message = request.form['message'] if len(input_message) >= 511: input_message = input_message[0:512] if "" == input_message.strip(): input_message = "Παρακαλώ εισάγετε το κείμενο του άρθρου" my_input = [input_message] preds = pipe(my_input, return_all_scores=True) output_dict = {'Αληθής (ποσοστό)': preds[0][0]['score'], 'Ψευδής (ποσοστό)': preds[0][1]['score']} print(output_dict) print(list(output_dict.keys()), list(output_dict.values())) props = [(round(float(v) * 100, 2)) for v in list(output_dict.values())] print(props) return render_template('result.html', mess=input_message, classes=list(output_dict.keys()), props=props) if __name__ == '__main__': app.run(debug=True)