Spaces:
Runtime error
Runtime error
fix CORS
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from flask_cors import CORS, cross_origin
|
|
5 |
import __main__
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
-
cors = CORS(app, supports_credentials=True, resources={r"/*": {"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 |
|
@@ -17,7 +17,7 @@ def home():
|
|
17 |
return render_template('index.html')
|
18 |
|
19 |
|
20 |
-
@app.route('/', methods=['POST'])
|
21 |
@cross_origin()
|
22 |
def recommend():
|
23 |
if request.method == "POST":
|
@@ -30,7 +30,6 @@ 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.headers['Access-Control-Allow-Origin'] = 'http://0.0.0.0'
|
34 |
response.headers['Access-Control-Allow-Methods'] = '*'
|
35 |
response.headers['Access-Control-Allow-Domain'] = '*'
|
36 |
response.headers['Access-Control-Allow-Credentials'] = True
|
@@ -39,20 +38,19 @@ def recommend():
|
|
39 |
except Exception as e:
|
40 |
return render_template('index.html', query=e)
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
|
|
44 |
|
45 |
-
@app.route('/', methods=['OPTIONS'])
|
46 |
-
def preflight():
|
47 |
-
resp = make_response("OK")
|
48 |
-
resp.status_code = 201
|
49 |
-
resp.headers['Access-Control-Allow-Origin'] = 'http://0.0.0.0'
|
50 |
-
resp.headers['Access-Control-Allow-Methods'] = '*'
|
51 |
-
resp.headers['Access-Control-Allow-Domain'] = '*'
|
52 |
-
resp.headers['Access-Control-Allow-Credentials'] = True
|
53 |
-
# Debug
|
54 |
-
print("Right")
|
55 |
-
return resp
|
56 |
|
57 |
|
58 |
def main():
|
|
|
5 |
import __main__
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
+
cors = CORS(app, supports_credentials=True, resources={r"/summarize/*": {"origins": "http://0.0.0.0/summarize"}})
|
9 |
# shortTokenizer = BartTokenizer.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
10 |
# shortModel = BartForConditionalGeneration.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
11 |
|
|
|
17 |
return render_template('index.html')
|
18 |
|
19 |
|
20 |
+
@app.route('/summarize', methods=['POST', 'OPTIONS'])
|
21 |
@cross_origin()
|
22 |
def recommend():
|
23 |
if request.method == "POST":
|
|
|
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.headers['Access-Control-Allow-Methods'] = '*'
|
34 |
response.headers['Access-Control-Allow-Domain'] = '*'
|
35 |
response.headers['Access-Control-Allow-Credentials'] = True
|
|
|
38 |
except Exception as e:
|
39 |
return render_template('index.html', query=e)
|
40 |
|
41 |
+
elif request.method == "OPTIONS":
|
42 |
+
resp = make_response("OK")
|
43 |
+
resp.status_code = 201
|
44 |
+
# resp.headers['Access-Control-Allow-Origin'] = 'http://0.0.0.0'
|
45 |
+
resp.headers['Access-Control-Allow-Methods'] = '*'
|
46 |
+
resp.headers['Access-Control-Allow-Domain'] = '*'
|
47 |
+
resp.headers['Access-Control-Allow-Credentials'] = True
|
48 |
+
# Debug
|
49 |
+
print("Right")
|
50 |
+
return resp
|
51 |
|
52 |
+
pass
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
|
56 |
def main():
|