Guest User

Untitled

a guest
Feb 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. def upload_file():
  2. try :
  3. return render_template('upload.html')
  4. except Exception as e :
  5. logging.warning(str(e))
  6. result_dict={"error":str(e)}
  7. return jsonify(result_dict)
  8.  
  9. @app.route('/uploader', methods = ['GET', 'POST'])
  10. def upload_file1():
  11. global w2v_model
  12. try:
  13. #w2v_model = session.get('w2v_model', None)
  14. if request.method == 'POST':
  15. file_id = '1-jLh3Zdi-gwIFEnrw0VKQnoLH8mof2hN'
  16. destination = os.getcwd()+"//search_strings.docx"
  17. download_file_from_google_drive(file_id, destination)
  18. f1 = request.files['file1']
  19. f1.save(secure_filename(f1.filename.replace(" ", "_")))
  20. #f2 = request.files['file2']
  21. #f2.save(secure_filename(f2.filename.replace(" ", "_")))
  22. logging.warning (f1.filename.replace(" ", "_"),w2v_model)
  23. questions,answers,results,flag=search_new.main(f1.filename.replace(" ", "_"),"search_strings.docx",w2v_model)
  24. if (flag):
  25. return jsonify({'error':"Documents with .doc extensions are not supported"})
  26. result_dict={}
  27. i=1
  28. for item1 , item2,item3 in zip (questions,answers,results):
  29. result_dict['{0}_question'.format(i)]=str(item1)
  30. result_dict['{0}_answer'.format(i)]=str(item2)
  31. j=1
  32. for item in item3 :
  33. result_dict['{0}_{1}_coinfidence'.format(i,j)]=str(item[1])
  34. result_dict['{0}_{1}_paragraph'.format(i,j)]=str(item[0])
  35. j+=1
  36. i+=1
  37. except Exception as e :
  38. result_dict={"error":str(e)}
  39. #return jsonify(result_dict)
  40. import pandas as pd
  41. data = [jsonify(result_dict)]
  42. df = pd.DataFrame.from_dict(data, orient='columns')
  43. #print(result_dict)
Add Comment
Please, Sign In to add comment