File size: 1,878 Bytes
9731642
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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)