datien228 commited on
Commit
887653b
1 Parent(s): d4d91e7

no fetch setting

Browse files
Files changed (2) hide show
  1. app.py +18 -20
  2. templates/index.html +11 -11
app.py CHANGED
@@ -1,5 +1,5 @@
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
 
@@ -15,26 +15,24 @@ def home():
15
  return render_template('index.html')
16
 
17
 
18
- @app.route('/summarize', methods=['GET', 'POST'])
19
- @cross_origin()
20
  def recommend():
21
- if request.method == "POST":
22
- # Get form data
23
- # request_data = request.args.get("input").get_json()
24
- # input_text = request_data['input_text']
25
- input_text = request.get_json()['input_text']
26
- print(input_text)
27
-
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
-
36
- except Exception as e:
37
- return render_template('index.html', query=e)
38
 
39
  pass
40
 
 
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
 
 
15
  return render_template('index.html')
16
 
17
 
18
+ @app.route('/summarize')
 
19
  def recommend():
20
+ # Get form data
21
+ # request_data = request.args.get("input").get_json()
22
+ # input_text = request_data['input_text']
23
+ input_text = request.args.get("input")
24
+ print(input_text)
25
+
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(message={'short': short_output_summary.strip(), 'long': long_output_summary.strip()})
30
+ response.headers.add("Access-Control-Allow-Origin", "*")
31
+ # Pass output summary to the output template
32
+ return response
33
+
34
+ except Exception as e:
35
+ return render_template('index.html', query=e)
 
36
 
37
  pass
38
 
templates/index.html CHANGED
@@ -188,17 +188,17 @@
188
  // ======= COMMUNICATE WITH FLSAK BACK END TO RUN ML TASK =======
189
 
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
  };
 
188
  // ======= COMMUNICATE WITH FLSAK BACK END TO RUN ML TASK =======
189
 
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?input=${jsonfile}`);
202
 
203
  return inferResponse.json();
204
  };