Spaces:
Runtime error
Runtime error
fix fetch request format
Browse files- app.py +4 -8
- templates/index.html +6 -6
app.py
CHANGED
@@ -1,10 +1,8 @@
|
|
1 |
-
from flask import Flask, render_template, request, jsonify, make_response
|
2 |
-
from flask.sessions import SecureCookieSessionInterface
|
3 |
from modules.model import summarize
|
4 |
import __main__
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
-
session_cookie = SecureCookieSessionInterface().get_signing_serializer(app)
|
8 |
# shortTokenizer = BartTokenizer.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
9 |
# shortModel = BartForConditionalGeneration.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
10 |
|
@@ -20,17 +18,15 @@ def home():
|
|
20 |
def recommend():
|
21 |
if request.method == "POST":
|
22 |
# Get form data
|
|
|
23 |
# input_text = request_data['input_text']
|
24 |
-
|
25 |
-
input_text
|
26 |
|
27 |
# Call the function summarize to run the text summarization
|
28 |
try:
|
29 |
short_output_summary, long_output_summary = summarize(input_text)
|
30 |
response = jsonify({'short': short_output_summary.strip(), 'long': long_output_summary.strip()})
|
31 |
-
same_cookie = session_cookie.dumps(dict(session))
|
32 |
-
response.headers.add("Set-Cookie", f"my_cookie={same_cookie}; Secure; HttpOnly; SameSite=None; Path=/;")
|
33 |
-
print(response)
|
34 |
# Pass output summary to the output template
|
35 |
return response
|
36 |
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify, make_response
|
|
|
2 |
from modules.model import summarize
|
3 |
import __main__
|
4 |
|
5 |
app = Flask(__name__)
|
|
|
6 |
# shortTokenizer = BartTokenizer.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
7 |
# shortModel = BartForConditionalGeneration.from_pretrained('sshleifer/distilbart-xsum-12-6')
|
8 |
|
|
|
18 |
def recommend():
|
19 |
if request.method == "POST":
|
20 |
# Get form data
|
21 |
+
# request_data = request.args.get("input").get_json()
|
22 |
# input_text = request_data['input_text']
|
23 |
+
input_text = request.get_json()['input_text']
|
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({'short': short_output_summary.strip(), 'long': long_output_summary.strip()})
|
|
|
|
|
|
|
30 |
# Pass output summary to the output template
|
31 |
return response
|
32 |
|
templates/index.html
CHANGED
@@ -190,12 +190,12 @@
|
|
190 |
const translateText = async (jsonfile) => {
|
191 |
const fetchSettings = {
|
192 |
method: 'POST',
|
193 |
-
|
194 |
-
headers: {
|
195 |
-
|
196 |
-
}
|
197 |
};
|
198 |
-
const inferResponse = await fetch(`/summarize
|
199 |
const inferJson = await inferResponse.json();
|
200 |
|
201 |
return inferJson;
|
@@ -217,7 +217,7 @@
|
|
217 |
// var data = {"input_text": textGenInput.value};
|
218 |
|
219 |
try {
|
220 |
-
data_out = await translateText(
|
221 |
$("#check").attr('checked', true);
|
222 |
$("#input_text").attr("readonly", false);
|
223 |
$("#load-noti").text("Completed")
|
|
|
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;
|
|
|
217 |
// var data = {"input_text": textGenInput.value};
|
218 |
|
219 |
try {
|
220 |
+
data_out = await translateText(textGenInput.value);
|
221 |
$("#check").attr('checked', true);
|
222 |
$("#input_text").attr("readonly", false);
|
223 |
$("#load-noti").text("Completed")
|