I have a Python web application where user upload an image and the code is generating a CSV from that image.
utils.py
:
def getCsv(output,im_bgr,im_name, output_dir):
df1 = pd.DataFrame({"class": class_names)
coords = ['x_start', 'y_start', 'x_end', 'y_end']
df2 = pd.DataFrame(data = frac_boxes, columns = coords)
df = pd.concat([df1,df2],axis=1)
# Give the filename you wish to save the file to
filename = output_dir+im_name.split('.')[0] + '.csv'
# Use this function to search for any files which match your filename
files_present = glob.glob(filename)
# if no matching files, write to csv, if there are matching files, print statement
if not files_present:
df.to_csv(filename, index = False)
else:
print ('WARNING: File ', filename, ' already exists!')
app.py
:
@app.route('/view_process', endpoint='view_process')
def process_files():
if not session.get('logged_in'):
return redirect(url_for('login_user'))
subprocess.run(['python', 'utils.py']) # call the utils.py that generates the csv
return render_template('view_process.html', message='Files processed successfully')
How to send the generated CSV back to app.py
(without saving to computer) and create a link in frontend for user to download it?
4