Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, render_template, request, redirect
- from werkzeug import secure_filename
- app = Flask(__name__)
- @app.route('/uploader', methods = ['GET','POST'])
- def upload():
- new=nrecs[['UserID','ProductID','Rating']]
- new['Recommendations'] = list(zip(new.ProductID, new.Rating))
- res=new[['UserID','Recommendations']]
- res_new=res['Recommendations'].groupby([res.UserID]).apply(list).reset_index()
- pd.options.display.max_colwidth = 500
- return render_template('simple.html', tables=[res_new.to_html(classes='data')], titles='')
- @app.route('/download-csv', methods = ['GET'])
- def download():
- return res_new.to_csv('Recommendations.csv')
- from flask import Flask, render_template, send_file
- app = Flask(__name__)
- @app.route('/uploader', methods = ['GET','POST'])
- def upload():
- new=nrecs[['UserID','ProductID','Rating']]
- new['Recommendations'] = list(zip(new.ProductID, new.Rating))
- res=new[['UserID','Recommendations']]
- res_new=res['Recommendations'].groupby([res.UserID]).apply(list).reset_index()
- # store the dataframe on the server.
- res_new.to_csv('Recommendations.csv')
- pd.options.display.max_colwidth = 500
- return render_template('simple.html', tables=[res_new.to_html(classes='data')], titles='')
- @app.route('/download-csv', methods = ['GET'])
- def download():
- # return the CSV file to the user here.
- return send_file('Recommendations.csv')
- from flask import Flask, render_template, session
- app = Flask(__name__)
- # secret key is needed for session
- app.secret_key = 'your secret key'
- @app.route('/uploader', methods = ['GET','POST'])
- def upload():
- new=nrecs[['UserID','ProductID','Rating']]
- new['Recommendations'] = list(zip(new.ProductID, new.Rating))
- res=new[['UserID','Recommendations']]
- res_new=res['Recommendations'].groupby([res.UserID]).apply(list).reset_index()
- session['reco_df'] = res_new
- pd.options.display.max_colwidth = 500
- return render_template('simple.html', tables=[res_new.to_html(classes='data')], titles='')
- @app.route('/download-csv', methods = ['GET'])
- def download():
- return session['reco_df'].to_csv('Recommendations.csv')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement