File size: 1,429 Bytes
d0ed3d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, render_template, request, jsonify
from modules.model import summarize
import __main__

app = Flask(__name__)
# shortTokenizer = BartTokenizer.from_pretrained('sshleifer/distilbart-xsum-12-6')
# shortModel = BartForConditionalGeneration.from_pretrained('sshleifer/distilbart-xsum-12-6')

# longTokenizer = BartTokenizer.from_pretrained('sshleifer/distilbart-cnn-12-6')
# longModel = BartForConditionalGeneration.from_pretrained('sshleifer/distilbart-cnn-12-6')

@app.route('/')
def home():
    return render_template('index.html')


@app.route('/summarize', methods=['GET', 'POST'])
def recommend():
    if request.method == "POST":
        # Get form data
        request_data = request.get_json()
        input_text = request_data['input_text']

        # Call the function summarize to run the text summarization
        try:
            short_output_summary, long_output_summary = summarize(input_text)
            # Pass output summary to the output template
            return jsonify({'short': short_output_summary.strip(), 'long': long_output_summary.strip()})

        except Exception as e:
            return render_template('index.html', query=e)

    pass

def main():
    app.config['TEMPLATES_AUTO_RELOAD'] = True
    app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
    app.run(debug=True)
    app.run()

if __name__ == '__main__':
    print("Loading BART model and tokenzier . . .")
    main()