-3

I am facing problem when deploying a text summarizer (LexRank) through Flask RESTful API. Please see below my code snippet

@app.route('/response/',methods = ['GET','POST'])
def response():
if request.method=='POST':
    text_org = request.json['foo']# I have defined this 'foo' in JQuery in UI
    text = json.loads(json.dumps(text_org))
    text = re.sub('[^A-Za-z0-9()[].]', ' ', str(text))
    text = text.lower()        
    if len(text.split())<=3:
        resp = ' '.join(['please give some more sentences.'])
        return resp
    else: 
        summarizer = LexRankSummarizer()
        parser = PlaintextParser.from_string(text,Tokenizer('english'))
        sum_1 = summarizer(parser.document,5)
        sum_lex=[]
        for sent in sum_1:
            resp_raw = sum_lex.append(str(sent))
            resp = ' '.join(resp_raw)
            return jsonify(resp)

After running this (with len(text) > 3) I am getting the following error

builtins.TypeError
TypeError: can only join an iterable

However, when I run a non Flask version of the above code, my result is coming properly. Can anybody please help?

pythondumb
  • 1,187
  • 1
  • 15
  • 30

1 Answers1

1

sum_lex.append(str(sent)) returns None, because appending to a list is done in-place. Because you're effectively running ' '.join(None), you get the error.

Try this instead:

sum_lex=[]
for sent in sum_1:
    sum_lex.append(str(sent))
resp = ' '.join(sum_lex)
return jsonify(resp)
Joost
  • 3,609
  • 2
  • 12
  • 29