Spaces:
Runtime error
Runtime error
File size: 2,581 Bytes
3e8fd1e d0ed3d4 1526bd4 d0ed3d4 bb9a0df 0ce49a8 d0ed3d4 6550152 a9d3211 d0ed3d4 f66d9d3 d0ed3d4 0ce49a8 f66d9d3 d0ed3d4 6550152 0ce49a8 6550152 0ce49a8 d0ed3d4 6550152 3e8fd1e d0ed3d4 205d5bb 41473e7 d0ed3d4 3e8fd1e |
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 56 57 58 59 60 61 62 63 64 65 66 67 68 |
from flask import Flask, render_template, request, jsonify, make_response
from modules.model import summarize
from flask_cors import CORS, cross_origin
import __main__
app = Flask(__name__)
CORS(app, supports_credentials=True)
app.config['CORS_ALLOW_HEADERS'] = 'Content-Type'
app.config['CORS_SUPPORTS_CREDENTIALS'] = 'True'
# 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=['POST', 'OPTIONS'])
@cross_origin()
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)
response = jsonify({'short': short_output_summary.strip(), 'long': long_output_summary.strip()})
# Pass output summary to the output template
response.headers.add('Access-Control-Allow-Origin', 'http://0.0.0.0:7860')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type, Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
response.headers.add('Access-Control-Allow-Credentials', 'true')
return response
except Exception as e:
return render_template('index.html', query=e)
elif request.method == "OPTIONS":
response = make_response("OK")
response.status_code = 201
response.headers.add('Access-Control-Allow-Origin', 'http://0.0.0.0:7860')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type, Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
response.headers.add('Access-Control-Allow-Credentials', 'true')
# Debug
print("Right")
return response
pass
def main():
# app.config['TEMPLATES_AUTO_RELOAD'] = True
# app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
# app.run(debug=True)
app.run(host='0.0.0.0', port=7860)
if __name__ == '__main__':
print("Loading BART model and tokenzier . . .")
main()
|