gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
use this code and modify it to temporarly create a random name, then get the image hash…
- User
use this code and modify it to temporarly create a random name, then get the image hash by passing the image path to hashew.hash_image("path") and rename it to the hash for i, img_url in enumerate(challenge_imgs): response = requests.get(img_url, headers=headers) img_name = hashew.hash_image("") img_path = os.path.join(directory, img_name)
- Assistant
import random import string
def generate_random_name(length): letters = string.ascii_lowercase return ''.join(random.choice(letters) for i in range(length))
for i, img_url in enumerate(challenge_imgs): response = requests.get(img_url, headers=headers) img_name = generate_random_name(10) img_path = os.path.join(directory, img_name)
# Save the image using the generated random name with open(img_path, 'wb') as f: f.write(response.content) # Get the image hash img_hash = hashew.hash_image(img_path) # Rename the image to the hash new_img_path = os.path.join(directory, img_hash) os.rename(img_path, new_img_path)