def index(): global current_version song = "" title = "" try: if request.method == 'POST': song = request.form['song'] if request.form['song'] else '' title = request.form['title'] if request.form['title'] else '' sentiment = 'neg' if text_analysis.has_positive_sentiment(title): sentiment = 'pos' # Get metaphors to be used in generation metaphors_n = [] metaphors_a = [] for x in title.split(): m = cc.get_metaphors(x, 30, sentiment) if len(m) > 1: metaphors_n += m[0] metaphors_a += m[1] final = '' final_list = [] for verse in song.split('\n'): sv = [x for x in verse.split() if 'r' not in x] lyrics = cc.generate_lyrics(markov_chain, len(sv), metaphors_n, metaphors_a, templates) final_list += [lyrics[0].replace('-', '')] final += cc.prettify(lyrics[0] + '.\n\n') current_version = random.randint(0, 6000) # Caching workaround lilypond.generate_pdf(song, final, title) return render_template('index.html', song=song, title=title, lyrics=final, lyricdata=' '.join(final_list), version=current_version) else: return render_template('index.html', song=song, title=title) except Exception, e: print e error = Error('Error on generation!', 'Error: ' + str(e)) return render_template('index.html', error=error, song=song, title=title)
def get_title(): return cc.prettify(generate_title())