Spaces:
Runtime error
Runtime error
fix CORS
Browse files- app.py +3 -3
- templates/index.html +4 -0
app.py
CHANGED
|
@@ -5,8 +5,7 @@ from flask_cors import CORS, cross_origin
|
|
| 5 |
import __main__
|
| 6 |
|
| 7 |
app = Flask(__name__)
|
| 8 |
-
app
|
| 9 |
-
cors = CORS(app, resources={r"/summarize": {"origins": "http://0.0.0.0:7860"}})
|
| 10 |
# shortTokenizer = BartTokenizer.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
| 11 |
# shortModel = BartForConditionalGeneration.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
| 12 |
|
|
@@ -19,7 +18,7 @@ def home():
|
|
| 19 |
|
| 20 |
|
| 21 |
@app.route('/summarize', methods=['POST'])
|
| 22 |
-
@cross_origin(
|
| 23 |
def recommend():
|
| 24 |
if request.method == "POST":
|
| 25 |
# Get form data
|
|
@@ -31,6 +30,7 @@ def recommend():
|
|
| 31 |
short_output_summary, long_output_summary = summarize(input_text)
|
| 32 |
response = jsonify({'short': short_output_summary.strip(), 'long': long_output_summary.strip()})
|
| 33 |
# Pass output summary to the output template
|
|
|
|
| 34 |
return response
|
| 35 |
|
| 36 |
except Exception as e:
|
|
|
|
| 5 |
import __main__
|
| 6 |
|
| 7 |
app = Flask(__name__)
|
| 8 |
+
CORS(app, support_credentials=True)
|
|
|
|
| 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 |
+
@cross_origin(supports_credentials=True)
|
| 22 |
def recommend():
|
| 23 |
if request.method == "POST":
|
| 24 |
# Get form data
|
|
|
|
| 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:
|
templates/index.html
CHANGED
|
@@ -196,6 +196,10 @@
|
|
| 196 |
data: JSON.stringify(data),
|
| 197 |
contentType: "application/json",
|
| 198 |
dataType: 'json',
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
beforeSend: function () {
|
| 200 |
$("#check").attr('checked', false);
|
| 201 |
$("#input_text").attr("readonly", true);
|
|
|
|
| 196 |
data: JSON.stringify(data),
|
| 197 |
contentType: "application/json",
|
| 198 |
dataType: 'json',
|
| 199 |
+
xhrFields: {
|
| 200 |
+
withCredentials: true
|
| 201 |
+
},
|
| 202 |
+
crossDomain: true,
|
| 203 |
beforeSend: function () {
|
| 204 |
$("#check").attr('checked', false);
|
| 205 |
$("#input_text").attr("readonly", true);
|