Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. from flask import Flask, render_template, request, redirect
  2. from werkzeug import secure_filename
  3. app = Flask(__name__)
  4.  
  5.  
  6. @app.route('/uploader', methods = ['GET','POST'])
  7. def upload():
  8. new=nrecs[['UserID','ProductID','Rating']]
  9. new['Recommendations'] = list(zip(new.ProductID, new.Rating))
  10. res=new[['UserID','Recommendations']]
  11. res_new=res['Recommendations'].groupby([res.UserID]).apply(list).reset_index()
  12. pd.options.display.max_colwidth = 500
  13. return render_template('simple.html', tables=[res_new.to_html(classes='data')], titles='')
  14.  
  15. @app.route('/download-csv', methods = ['GET'])
  16. def download():
  17. return res_new.to_csv('Recommendations.csv')
  18.  
  19. from flask import Flask, render_template, send_file
  20. app = Flask(__name__)
  21.  
  22. @app.route('/uploader', methods = ['GET','POST'])
  23. def upload():
  24. new=nrecs[['UserID','ProductID','Rating']]
  25. new['Recommendations'] = list(zip(new.ProductID, new.Rating))
  26. res=new[['UserID','Recommendations']]
  27. res_new=res['Recommendations'].groupby([res.UserID]).apply(list).reset_index()
  28.  
  29. # store the dataframe on the server.
  30. res_new.to_csv('Recommendations.csv')
  31.  
  32. pd.options.display.max_colwidth = 500
  33. return render_template('simple.html', tables=[res_new.to_html(classes='data')], titles='')
  34.  
  35. @app.route('/download-csv', methods = ['GET'])
  36. def download():
  37.  
  38. # return the CSV file to the user here.
  39. return send_file('Recommendations.csv')
  40.  
  41. from flask import Flask, render_template, session
  42. app = Flask(__name__)
  43. # secret key is needed for session
  44. app.secret_key = 'your secret key'
  45.  
  46. @app.route('/uploader', methods = ['GET','POST'])
  47. def upload():
  48. new=nrecs[['UserID','ProductID','Rating']]
  49. new['Recommendations'] = list(zip(new.ProductID, new.Rating))
  50. res=new[['UserID','Recommendations']]
  51. res_new=res['Recommendations'].groupby([res.UserID]).apply(list).reset_index()
  52.  
  53. session['reco_df'] = res_new
  54.  
  55. pd.options.display.max_colwidth = 500
  56. return render_template('simple.html', tables=[res_new.to_html(classes='data')], titles='')
  57.  
  58. @app.route('/download-csv', methods = ['GET'])
  59. def download():
  60. return session['reco_df'].to_csv('Recommendations.csv')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement