[Python] Create a download link for generated CSV file in flask [duplicate]

Discussão em 'Python' iniciado por Stack, Agosto 14, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Python web application where user upload an image and the code is generating a CSV from that image. What i need is to return that csv to app.py and display it on the frontend for user to download it. How i achieve that?

    app.py

    # Route to show processed files
    @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', 'inference.py'])

    return render_template('view_process.html', message='Files processed sucessfully')


    Inference.py

    from utils import *

    processInputs(cfg, outputs, im_bgr_list, output_directory, im_names)


    Utils.py

    def processInputs(cfg, outputs, im_bgr_list, output_directory, im_names):

    getSegmentationCsv(outputs,im_bgr_list,im_names,output_directory)

    def getSegmentationCsv(output,im_bgr,im_name, output_dir):
    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)

    Continue reading...

Compartilhe esta Página