Write me a python code that processes a CSV file with the following structure…
- User
Write me a python code that processes a CSV file with the following structure ["Name","URL","Rating"], download each image under the URL row as save as PNG, use the Name as the file name and save it under a subfolder using the Rating as name, add a tkinter GUI to let me choose the CSV file and output path.
- Assistant
Sure, here is a sample code to accomplish this task:
import tkinter as tk from tkinter import filedialog import pandas as pd import urllib.request
def process_csv(): root = tk.Tk() root.withdraw()
codecsv_file = filedialog.askopenfilename(title='Select the CSV file', filetypes=[('CSV Files', '*.csv')]) output_path = filedialog.askdirectory(title='Select the output folder') df = pd.read_csv(csv_file) for i, row in df.iterrows(): name = row['Name'] url = row['URL'] rating = row['Rating'] folder = output_path + '/' + rating if not os.path.exists(folder): os.makedirs(folder) image_path = folder + '/' + name + '.png' urllib.request.urlretrieve(url, image_path)process_csv()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →