Spaces:
Runtime error
Runtime error
fix CORS
Browse files- app.py +21 -5
- templates/index.html +1 -0
app.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
-
from flask import Flask, render_template, request, jsonify
|
| 2 |
from modules.model import summarize
|
| 3 |
from flask_cors import CORS, cross_origin
|
| 4 |
|
| 5 |
import __main__
|
| 6 |
|
| 7 |
app = Flask(__name__)
|
| 8 |
-
CORS(app,
|
| 9 |
# shortTokenizer = BartTokenizer.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
| 10 |
# shortModel = BartForConditionalGeneration.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
| 11 |
|
|
@@ -18,7 +18,6 @@ def home():
|
|
| 18 |
|
| 19 |
|
| 20 |
@app.route('/summarize', methods=['POST'])
|
| 21 |
-
@cross_origin(supports_credentials=True)
|
| 22 |
def recommend():
|
| 23 |
if request.method == "POST":
|
| 24 |
# Get form data
|
|
@@ -30,7 +29,10 @@ def recommend():
|
|
| 30 |
short_output_summary, long_output_summary = summarize(input_text)
|
| 31 |
response = jsonify({'short': short_output_summary.strip(), 'long': long_output_summary.strip()})
|
| 32 |
# Pass output summary to the output template
|
| 33 |
-
response
|
|
|
|
|
|
|
|
|
|
| 34 |
return response
|
| 35 |
|
| 36 |
except Exception as e:
|
|
@@ -38,6 +40,20 @@ def recommend():
|
|
| 38 |
|
| 39 |
pass
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
def main():
|
| 42 |
# app.config['TEMPLATES_AUTO_RELOAD'] = True
|
| 43 |
# app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
|
|
@@ -46,4 +62,4 @@ def main():
|
|
| 46 |
|
| 47 |
if __name__ == '__main__':
|
| 48 |
print("Loading BART model and tokenzier . . .")
|
| 49 |
-
main()
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request, jsonify, make_response
|
| 2 |
from modules.model import summarize
|
| 3 |
from flask_cors import CORS, cross_origin
|
| 4 |
|
| 5 |
import __main__
|
| 6 |
|
| 7 |
app = Flask(__name__)
|
| 8 |
+
cors = CORS(app, supports_credentials=True, resources={r"/api/*": {"origins": "http://0.0.0.0"}})
|
| 9 |
# shortTokenizer = BartTokenizer.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
| 10 |
# shortModel = BartForConditionalGeneration.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
| 11 |
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
@app.route('/summarize', methods=['POST'])
|
|
|
|
| 21 |
def recommend():
|
| 22 |
if request.method == "POST":
|
| 23 |
# Get form data
|
|
|
|
| 29 |
short_output_summary, long_output_summary = summarize(input_text)
|
| 30 |
response = jsonify({'short': short_output_summary.strip(), 'long': long_output_summary.strip()})
|
| 31 |
# Pass output summary to the output template
|
| 32 |
+
response.headers['Access-Control-Allow-Origin'] = 'http://0.0.0.0'
|
| 33 |
+
response.headers['Access-Control-Allow-Methods'] = '*'
|
| 34 |
+
response.headers['Access-Control-Allow-Domain'] = '*'
|
| 35 |
+
response.headers['Access-Control-Allow-Credentials'] = True
|
| 36 |
return response
|
| 37 |
|
| 38 |
except Exception as e:
|
|
|
|
| 40 |
|
| 41 |
pass
|
| 42 |
|
| 43 |
+
|
| 44 |
+
@app.route('/summarize', methods=['OPTIONS'])
|
| 45 |
+
def preflight():
|
| 46 |
+
resp = make_response("OK")
|
| 47 |
+
resp.status_code = 201
|
| 48 |
+
resp.headers['Access-Control-Allow-Origin'] = 'http://0.0.0.0'
|
| 49 |
+
resp.headers['Access-Control-Allow-Methods'] = '*'
|
| 50 |
+
resp.headers['Access-Control-Allow-Domain'] = '*'
|
| 51 |
+
resp.headers['Access-Control-Allow-Credentials'] = True
|
| 52 |
+
# Debug
|
| 53 |
+
print("Right")
|
| 54 |
+
return resp
|
| 55 |
+
|
| 56 |
+
|
| 57 |
def main():
|
| 58 |
# app.config['TEMPLATES_AUTO_RELOAD'] = True
|
| 59 |
# app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
|
|
|
|
| 62 |
|
| 63 |
if __name__ == '__main__':
|
| 64 |
print("Loading BART model and tokenzier . . .")
|
| 65 |
+
main()
|
templates/index.html
CHANGED
|
@@ -194,6 +194,7 @@
|
|
| 194 |
type: 'POST',
|
| 195 |
url: '/summarize',
|
| 196 |
data: JSON.stringify(data),
|
|
|
|
| 197 |
contentType: "application/json",
|
| 198 |
dataType: 'json',
|
| 199 |
xhrFields: {
|
|
|
|
| 194 |
type: 'POST',
|
| 195 |
url: '/summarize',
|
| 196 |
data: JSON.stringify(data),
|
| 197 |
+
headers: {'Access-Control-Allow-Origin':'*'},
|
| 198 |
contentType: "application/json",
|
| 199 |
dataType: 'json',
|
| 200 |
xhrFields: {
|