datien228 commited on
Commit
d4d91e7
1 Parent(s): 9c55c18

add cors dependency, add headers

Browse files
Files changed (3) hide show
  1. app.py +4 -1
  2. requirements.txt +1 -0
  3. templates/index.html +7 -5
app.py CHANGED
@@ -1,4 +1,5 @@
1
  from flask import Flask, render_template, request, jsonify, make_response
 
2
  from modules.model import summarize
3
  import __main__
4
 
@@ -15,6 +16,7 @@ def home():
15
 
16
 
17
  @app.route('/summarize', methods=['GET', 'POST'])
 
18
  def recommend():
19
  if request.method == "POST":
20
  # Get form data
@@ -26,7 +28,8 @@ def recommend():
26
  # Call the function summarize to run the text summarization
27
  try:
28
  short_output_summary, long_output_summary = summarize(input_text)
29
- response = jsonify({'short': short_output_summary.strip(), 'long': long_output_summary.strip()})
 
30
  # Pass output summary to the output template
31
  return response
32
 
 
1
  from flask import Flask, render_template, request, jsonify, make_response
2
+ from flask_cors import CORS, cross_origin
3
  from modules.model import summarize
4
  import __main__
5
 
 
16
 
17
 
18
  @app.route('/summarize', methods=['GET', 'POST'])
19
+ @cross_origin()
20
  def recommend():
21
  if request.method == "POST":
22
  # Get form data
 
28
  # Call the function summarize to run the text summarization
29
  try:
30
  short_output_summary, long_output_summary = summarize(input_text)
31
+ response = jsonify(message={'short': short_output_summary.strip(), 'long': long_output_summary.strip()})
32
+ response.headers.add("Access-Control-Allow-Origin", "*")
33
  # Pass output summary to the output template
34
  return response
35
 
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  torch==1.11.0
2
  Flask==2.1.0
3
  transformers==4.20.0
 
 
1
  torch==1.11.0
2
  Flask==2.1.0
3
  transformers==4.20.0
4
+ flask_cors==3.0.10
templates/index.html CHANGED
@@ -190,15 +190,17 @@
190
  const translateText = async (jsonfile) => {
191
  const fetchSettings = {
192
  method: 'POST',
 
 
193
  body: JSON.stringify({"input_text": jsonfile}),
194
- headers: new Headers({
195
- "content-type": "application/json"
196
- })
 
197
  };
198
  const inferResponse = await fetch(`/summarize`, fetchSettings);
199
- const inferJson = await inferResponse.json();
200
 
201
- return inferJson;
202
  };
203
 
204
  const textGenForm = document.querySelector('#input_form');
 
190
  const translateText = async (jsonfile) => {
191
  const fetchSettings = {
192
  method: 'POST',
193
+ mode: 'cors',
194
+ credentials: 'same-origin',
195
  body: JSON.stringify({"input_text": jsonfile}),
196
+ headers: {
197
+ "Content-Type": "application/json"
198
+ },
199
+ referrerPolicy: 'no-referrer'
200
  };
201
  const inferResponse = await fetch(`/summarize`, fetchSettings);
 
202
 
203
+ return inferResponse.json();
204
  };
205
 
206
  const textGenForm = document.querySelector('#input_form');