Download image_parser.py from friedeggy/Lab1: direct link, hf CLI and curl.
- Browser
- Download file 527 Bytes
-
https://huggingface.co/spaces/friedeggy/Lab1/resolve/main/image_parser.py
- Command line
-
hf download hf://spaces/friedeggy/Lab1/image_parser.py
-
curl -L -o image_parser.py https://huggingface.co/spaces/friedeggy/Lab1/resolve/main/image_parser.py
527 Bytes
| import gradio as gr | |
| import os | |
| from PIL import Image | |
| folder = "images" | |
| img_list = os.listdir(folder) | |
| #looks at the colors in an image and saves the findings to a file | |
| with open("imageRGBs.txt", 'w') as color_file: | |
| for image_name in img_list: | |
| im = Image.open(folder+"/"+image_name) | |
| #Returns the three main colors of the image | |
| im2 = im.quantize(colors=3, method=2) | |
| rgb = im2.getpalette()[:9] | |
| b = list(map(str, rgb)) | |
| color_file.write(' '.join(b) + ";" + image_name + "\n") | |