File size: 1,419 Bytes
e76045d
887653b
d0ed3d4
 
 
 
 
 
 
 
 
 
e76045d
d0ed3d4
 
 
 
e76045d
d0ed3d4
887653b
 
 
46dd2fb
ca8dff8
887653b
 
 
 
 
ca8dff8
887653b
 
 
 
 
d0ed3d4
6550152
3e8fd1e
d0ed3d4
 
e76045d
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
from flask import Flask, render_template, request, jsonify
# from flask_cors import CORS, cross_origin
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")
def recommend():
    # Get form data
    # request_data = request.args.get("input").get_json()
    # input_text = request_data['input_text']
    request_data = request.json.get("input")
    input_text = request_data['input_text']
    print(input_text)

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

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

    pass

if __name__ == '__main__':
    print("Loading BART model and tokenzier . . .")
    app.run(host="0.0.0.0", port=7860)