Spaces:
Runtime error
Runtime error
fix CORS
Browse files
app.py
CHANGED
@@ -5,7 +5,9 @@ from flask_cors import CORS, cross_origin
|
|
5 |
import __main__
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
-
|
|
|
|
|
9 |
# shortTokenizer = BartTokenizer.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
10 |
# shortModel = BartForConditionalGeneration.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
11 |
|
@@ -30,24 +32,25 @@ 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
|
34 |
-
response.headers
|
35 |
-
response.headers
|
|
|
36 |
return response
|
37 |
|
38 |
except Exception as e:
|
39 |
return render_template('index.html', query=e)
|
40 |
|
41 |
elif request.method == "OPTIONS":
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
# Debug
|
49 |
print("Right")
|
50 |
-
return
|
51 |
|
52 |
pass
|
53 |
|
|
|
5 |
import __main__
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
+
CORS(app, resources={r"/*": {"origins": "http://0.0.0.0:7860"}}, supports_credentials=True)
|
9 |
+
app.config['CORS_ALLOW_HEADERS'] = 'Content-Type'
|
10 |
+
app.config['CORS_SUPPORTS_CREDENTIALS'] = 'True'
|
11 |
# shortTokenizer = BartTokenizer.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
12 |
# shortModel = BartForConditionalGeneration.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
13 |
|
|
|
32 |
short_output_summary, long_output_summary = summarize(input_text)
|
33 |
response = jsonify({'short': short_output_summary.strip(), 'long': long_output_summary.strip()})
|
34 |
# Pass output summary to the output template
|
35 |
+
response.headers.add('Access-Control-Allow-Origin', 'http://0.0.0.0:7860')
|
36 |
+
response.headers.add('Access-Control-Allow-Headers', 'Content-Type, Authorization')
|
37 |
+
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
|
38 |
+
response.headers.add('Access-Control-Allow-Credentials', 'true')
|
39 |
return response
|
40 |
|
41 |
except Exception as e:
|
42 |
return render_template('index.html', query=e)
|
43 |
|
44 |
elif request.method == "OPTIONS":
|
45 |
+
response = make_response("OK")
|
46 |
+
response.status_code = 201
|
47 |
+
response.headers.add('Access-Control-Allow-Origin', 'http://0.0.0.0:7860')
|
48 |
+
response.headers.add('Access-Control-Allow-Headers', 'Content-Type, Authorization')
|
49 |
+
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
|
50 |
+
response.headers.add('Access-Control-Allow-Credentials', 'true')
|
51 |
# Debug
|
52 |
print("Right")
|
53 |
+
return response
|
54 |
|
55 |
pass
|
56 |
|