TheLastBen
commited on
Commit
•
2054d55
1
Parent(s):
4a4e12f
Upload 4 files
Browse files- Scripts/mainpaperspacev1.py +8 -9
- Scripts/mainpaperspacev2.py +9 -10
- Scripts/sdxllorapps.py +22 -13
Scripts/mainpaperspacev1.py
CHANGED
@@ -3,7 +3,7 @@ from subprocess import call, getoutput
|
|
3 |
from IPython.display import display
|
4 |
import ipywidgets as widgets
|
5 |
import io
|
6 |
-
from PIL import Image, ImageDraw
|
7 |
import fileinput
|
8 |
import time
|
9 |
import os
|
@@ -539,12 +539,12 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
539 |
identifier=filename.split(".")[0]
|
540 |
new_path_with_file = os.path.join(INSTANCE_DIR, filename)
|
541 |
file = Image.open(IMAGES_FOLDER_OPTIONAL+"/"+filename)
|
542 |
-
|
543 |
-
|
|
|
544 |
if file.size !=(Crop_size, Crop_size):
|
545 |
image=crop_image(file, Crop_size)
|
546 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
547 |
-
image[0] = image[0].convert("RGB")
|
548 |
image[0].save(new_path_with_file, format="JPEG", quality = 100)
|
549 |
else:
|
550 |
image[0].save(new_path_with_file, format=extension.upper())
|
@@ -570,17 +570,17 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
570 |
img = Image.open(io.BytesIO(file['content']))
|
571 |
extension = filename.split(".")[-1]
|
572 |
identifier=filename.split(".")[0]
|
|
|
|
|
573 |
|
574 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
575 |
-
img=img.convert("RGB")
|
576 |
img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
|
577 |
else:
|
578 |
img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
|
579 |
|
580 |
new_path_with_file = os.path.join(INSTANCE_DIR, filename)
|
581 |
file = Image.open(new_path_with_file)
|
582 |
-
width, height = file.size
|
583 |
-
image = img
|
584 |
if file.size !=(Crop_size, Crop_size):
|
585 |
image=crop_image(file, Crop_size)
|
586 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
@@ -592,12 +592,11 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
592 |
for file in tqdm(uploader.value, bar_format=' |{bar:15}| {n_fmt}/{total_fmt} Uploaded'):
|
593 |
filename = file['name']
|
594 |
img = Image.open(io.BytesIO(file['content']))
|
595 |
-
|
596 |
extension = filename.split(".")[-1]
|
597 |
identifier=filename.split(".")[0]
|
598 |
|
599 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
600 |
-
img=img.convert("RGB")
|
601 |
img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
|
602 |
else:
|
603 |
img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
|
|
|
3 |
from IPython.display import display
|
4 |
import ipywidgets as widgets
|
5 |
import io
|
6 |
+
from PIL import Image, ImageDraw, ImageOps
|
7 |
import fileinput
|
8 |
import time
|
9 |
import os
|
|
|
539 |
identifier=filename.split(".")[0]
|
540 |
new_path_with_file = os.path.join(INSTANCE_DIR, filename)
|
541 |
file = Image.open(IMAGES_FOLDER_OPTIONAL+"/"+filename)
|
542 |
+
file=file.convert("RGB")
|
543 |
+
file=ImageOps.exif_transpose(file)
|
544 |
+
width, height = file.size
|
545 |
if file.size !=(Crop_size, Crop_size):
|
546 |
image=crop_image(file, Crop_size)
|
547 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
|
|
548 |
image[0].save(new_path_with_file, format="JPEG", quality = 100)
|
549 |
else:
|
550 |
image[0].save(new_path_with_file, format=extension.upper())
|
|
|
570 |
img = Image.open(io.BytesIO(file['content']))
|
571 |
extension = filename.split(".")[-1]
|
572 |
identifier=filename.split(".")[0]
|
573 |
+
img=img.convert("RGB")
|
574 |
+
img=ImageOps.exif_transpose(img)
|
575 |
|
576 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
|
|
577 |
img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
|
578 |
else:
|
579 |
img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
|
580 |
|
581 |
new_path_with_file = os.path.join(INSTANCE_DIR, filename)
|
582 |
file = Image.open(new_path_with_file)
|
583 |
+
width, height = file.size
|
|
|
584 |
if file.size !=(Crop_size, Crop_size):
|
585 |
image=crop_image(file, Crop_size)
|
586 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
|
|
592 |
for file in tqdm(uploader.value, bar_format=' |{bar:15}| {n_fmt}/{total_fmt} Uploaded'):
|
593 |
filename = file['name']
|
594 |
img = Image.open(io.BytesIO(file['content']))
|
595 |
+
img=img.convert("RGB")
|
596 |
extension = filename.split(".")[-1]
|
597 |
identifier=filename.split(".")[0]
|
598 |
|
599 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
|
|
600 |
img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
|
601 |
else:
|
602 |
img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
|
Scripts/mainpaperspacev2.py
CHANGED
@@ -3,7 +3,7 @@ from subprocess import call, getoutput
|
|
3 |
from IPython.display import display
|
4 |
import ipywidgets as widgets
|
5 |
import io
|
6 |
-
from PIL import Image, ImageDraw
|
7 |
import fileinput
|
8 |
import time
|
9 |
import os
|
@@ -623,12 +623,12 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
623 |
identifier=filename.split(".")[0]
|
624 |
new_path_with_file = os.path.join(INSTANCE_DIR, filename)
|
625 |
file = Image.open(IMAGES_FOLDER_OPTIONAL+"/"+filename)
|
626 |
-
|
627 |
-
|
|
|
628 |
if file.size !=(Crop_size, Crop_size):
|
629 |
image=crop_image(file, Crop_size)
|
630 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
631 |
-
image[0] = image[0].convert("RGB")
|
632 |
image[0].save(new_path_with_file, format="JPEG", quality = 100)
|
633 |
else:
|
634 |
image[0].save(new_path_with_file, format=extension.upper())
|
@@ -646,7 +646,7 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
646 |
filename = file['name']
|
647 |
if filename.split(".")[-1]=="txt":
|
648 |
with open(CAPTIONS_DIR+'/'+filename, 'w') as f:
|
649 |
-
f.write(bytes(file['content']).decode())
|
650 |
up=[file for file in uploader.value if not file['name'].endswith('.txt')]
|
651 |
if Crop_images:
|
652 |
for file in tqdm(up, bar_format=' |{bar:15}| {n_fmt}/{total_fmt} Uploaded'):
|
@@ -654,17 +654,17 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
654 |
img = Image.open(io.BytesIO(file['content']))
|
655 |
extension = filename.split(".")[-1]
|
656 |
identifier=filename.split(".")[0]
|
|
|
|
|
657 |
|
658 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
659 |
-
img=img.convert("RGB")
|
660 |
img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
|
661 |
else:
|
662 |
img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
|
663 |
|
664 |
new_path_with_file = os.path.join(INSTANCE_DIR, filename)
|
665 |
file = Image.open(new_path_with_file)
|
666 |
-
width, height = file.size
|
667 |
-
image = img
|
668 |
if file.size !=(Crop_size, Crop_size):
|
669 |
image=crop_image(file, Crop_size)
|
670 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
@@ -676,12 +676,11 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
676 |
for file in tqdm(uploader.value, bar_format=' |{bar:15}| {n_fmt}/{total_fmt} Uploaded'):
|
677 |
filename = file['name']
|
678 |
img = Image.open(io.BytesIO(file['content']))
|
679 |
-
|
680 |
extension = filename.split(".")[-1]
|
681 |
identifier=filename.split(".")[0]
|
682 |
|
683 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
684 |
-
img=img.convert("RGB")
|
685 |
img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
|
686 |
else:
|
687 |
img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
|
|
|
3 |
from IPython.display import display
|
4 |
import ipywidgets as widgets
|
5 |
import io
|
6 |
+
from PIL import Image, ImageDraw, ImageOps
|
7 |
import fileinput
|
8 |
import time
|
9 |
import os
|
|
|
623 |
identifier=filename.split(".")[0]
|
624 |
new_path_with_file = os.path.join(INSTANCE_DIR, filename)
|
625 |
file = Image.open(IMAGES_FOLDER_OPTIONAL+"/"+filename)
|
626 |
+
file=file.convert("RGB")
|
627 |
+
file=ImageOps.exif_transpose(file)
|
628 |
+
width, height = file.size
|
629 |
if file.size !=(Crop_size, Crop_size):
|
630 |
image=crop_image(file, Crop_size)
|
631 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
|
|
632 |
image[0].save(new_path_with_file, format="JPEG", quality = 100)
|
633 |
else:
|
634 |
image[0].save(new_path_with_file, format=extension.upper())
|
|
|
646 |
filename = file['name']
|
647 |
if filename.split(".")[-1]=="txt":
|
648 |
with open(CAPTIONS_DIR+'/'+filename, 'w') as f:
|
649 |
+
f.write(bytes(file['content']).decode())
|
650 |
up=[file for file in uploader.value if not file['name'].endswith('.txt')]
|
651 |
if Crop_images:
|
652 |
for file in tqdm(up, bar_format=' |{bar:15}| {n_fmt}/{total_fmt} Uploaded'):
|
|
|
654 |
img = Image.open(io.BytesIO(file['content']))
|
655 |
extension = filename.split(".")[-1]
|
656 |
identifier=filename.split(".")[0]
|
657 |
+
img=img.convert("RGB")
|
658 |
+
img=ImageOps.exif_transpose(img)
|
659 |
|
660 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
|
|
661 |
img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
|
662 |
else:
|
663 |
img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
|
664 |
|
665 |
new_path_with_file = os.path.join(INSTANCE_DIR, filename)
|
666 |
file = Image.open(new_path_with_file)
|
667 |
+
width, height = file.size
|
|
|
668 |
if file.size !=(Crop_size, Crop_size):
|
669 |
image=crop_image(file, Crop_size)
|
670 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
|
|
676 |
for file in tqdm(uploader.value, bar_format=' |{bar:15}| {n_fmt}/{total_fmt} Uploaded'):
|
677 |
filename = file['name']
|
678 |
img = Image.open(io.BytesIO(file['content']))
|
679 |
+
img=img.convert("RGB")
|
680 |
extension = filename.split(".")[-1]
|
681 |
identifier=filename.split(".")[0]
|
682 |
|
683 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
|
|
684 |
img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
|
685 |
else:
|
686 |
img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
|
Scripts/sdxllorapps.py
CHANGED
@@ -3,7 +3,7 @@ from subprocess import call, getoutput, Popen
|
|
3 |
from IPython.display import display
|
4 |
import ipywidgets as widgets
|
5 |
import io
|
6 |
-
from PIL import Image, ImageDraw
|
7 |
import fileinput
|
8 |
import time
|
9 |
import os
|
@@ -445,9 +445,9 @@ def uplder(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDE
|
|
445 |
|
446 |
|
447 |
|
448 |
-
def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader):
|
|
|
449 |
|
450 |
-
from tqdm import tqdm
|
451 |
if Remove_existing_instance_images:
|
452 |
if os.path.exists(str(INSTANCE_DIR)):
|
453 |
call("rm -r " +INSTANCE_DIR, shell=True)
|
@@ -462,6 +462,7 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
462 |
|
463 |
|
464 |
if IMAGES_FOLDER_OPTIONAL !="":
|
|
|
465 |
if os.path.exists(IMAGES_FOLDER_OPTIONAL+"/.ipynb_checkpoints"):
|
466 |
call('rm -r '+IMAGES_FOLDER_OPTIONAL+'/.ipynb_checkpoints', shell=True)
|
467 |
|
@@ -476,12 +477,12 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
476 |
identifier=filename.split(".")[0]
|
477 |
new_path_with_file = os.path.join(INSTANCE_DIR, filename)
|
478 |
file = Image.open(IMAGES_FOLDER_OPTIONAL+"/"+filename)
|
479 |
-
|
480 |
-
|
|
|
481 |
if file.size !=(Crop_size, Crop_size):
|
482 |
image=crop_image(file, Crop_size)
|
483 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
484 |
-
image[0] = image[0].convert("RGB")
|
485 |
image[0].save(new_path_with_file, format="JPEG", quality = 100)
|
486 |
else:
|
487 |
image[0].save(new_path_with_file, format=extension.upper())
|
@@ -499,7 +500,7 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
499 |
filename = file['name']
|
500 |
if filename.split(".")[-1]=="txt":
|
501 |
with open(CAPTIONS_DIR+'/'+filename, 'w') as f:
|
502 |
-
f.write(bytes(file['content']).decode())
|
503 |
up=[file for file in uploader.value if not file['name'].endswith('.txt')]
|
504 |
if Crop_images:
|
505 |
for file in tqdm(up, bar_format=' |{bar:15}| {n_fmt}/{total_fmt} Uploaded'):
|
@@ -507,17 +508,17 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
507 |
img = Image.open(io.BytesIO(file['content']))
|
508 |
extension = filename.split(".")[-1]
|
509 |
identifier=filename.split(".")[0]
|
|
|
|
|
510 |
|
511 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
512 |
-
img=img.convert("RGB")
|
513 |
img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
|
514 |
else:
|
515 |
img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
|
516 |
|
517 |
new_path_with_file = os.path.join(INSTANCE_DIR, filename)
|
518 |
file = Image.open(new_path_with_file)
|
519 |
-
width, height = file.size
|
520 |
-
image = img
|
521 |
if file.size !=(Crop_size, Crop_size):
|
522 |
image=crop_image(file, Crop_size)
|
523 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
@@ -529,16 +530,23 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
529 |
for file in tqdm(uploader.value, bar_format=' |{bar:15}| {n_fmt}/{total_fmt} Uploaded'):
|
530 |
filename = file['name']
|
531 |
img = Image.open(io.BytesIO(file['content']))
|
532 |
-
|
533 |
extension = filename.split(".")[-1]
|
534 |
identifier=filename.split(".")[0]
|
535 |
|
536 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
537 |
-
img=img.convert("RGB")
|
538 |
img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
|
539 |
else:
|
540 |
img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
|
541 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
542 |
|
543 |
os.chdir(INSTANCE_DIR)
|
544 |
call('find . -name "* *" -type f | rename ' "'s/ /-/g'", shell=True)
|
@@ -548,6 +556,7 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
|
|
548 |
|
549 |
|
550 |
|
|
|
551 |
def caption(CAPTIONS_DIR, INSTANCE_DIR):
|
552 |
|
553 |
paths=""
|
|
|
3 |
from IPython.display import display
|
4 |
import ipywidgets as widgets
|
5 |
import io
|
6 |
+
from PIL import Image, ImageDraw, ImageOps
|
7 |
import fileinput
|
8 |
import time
|
9 |
import os
|
|
|
445 |
|
446 |
|
447 |
|
448 |
+
def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader, ren):
|
449 |
+
|
450 |
|
|
|
451 |
if Remove_existing_instance_images:
|
452 |
if os.path.exists(str(INSTANCE_DIR)):
|
453 |
call("rm -r " +INSTANCE_DIR, shell=True)
|
|
|
462 |
|
463 |
|
464 |
if IMAGES_FOLDER_OPTIONAL !="":
|
465 |
+
|
466 |
if os.path.exists(IMAGES_FOLDER_OPTIONAL+"/.ipynb_checkpoints"):
|
467 |
call('rm -r '+IMAGES_FOLDER_OPTIONAL+'/.ipynb_checkpoints', shell=True)
|
468 |
|
|
|
477 |
identifier=filename.split(".")[0]
|
478 |
new_path_with_file = os.path.join(INSTANCE_DIR, filename)
|
479 |
file = Image.open(IMAGES_FOLDER_OPTIONAL+"/"+filename)
|
480 |
+
file=file.convert("RGB")
|
481 |
+
file=ImageOps.exif_transpose(file)
|
482 |
+
width, height = file.size
|
483 |
if file.size !=(Crop_size, Crop_size):
|
484 |
image=crop_image(file, Crop_size)
|
485 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
|
|
486 |
image[0].save(new_path_with_file, format="JPEG", quality = 100)
|
487 |
else:
|
488 |
image[0].save(new_path_with_file, format=extension.upper())
|
|
|
500 |
filename = file['name']
|
501 |
if filename.split(".")[-1]=="txt":
|
502 |
with open(CAPTIONS_DIR+'/'+filename, 'w') as f:
|
503 |
+
f.write(bytes(file['content']).decode())
|
504 |
up=[file for file in uploader.value if not file['name'].endswith('.txt')]
|
505 |
if Crop_images:
|
506 |
for file in tqdm(up, bar_format=' |{bar:15}| {n_fmt}/{total_fmt} Uploaded'):
|
|
|
508 |
img = Image.open(io.BytesIO(file['content']))
|
509 |
extension = filename.split(".")[-1]
|
510 |
identifier=filename.split(".")[0]
|
511 |
+
img=img.convert("RGB")
|
512 |
+
img=ImageOps.exif_transpose(img)
|
513 |
|
514 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
|
|
515 |
img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
|
516 |
else:
|
517 |
img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
|
518 |
|
519 |
new_path_with_file = os.path.join(INSTANCE_DIR, filename)
|
520 |
file = Image.open(new_path_with_file)
|
521 |
+
width, height = file.size
|
|
|
522 |
if file.size !=(Crop_size, Crop_size):
|
523 |
image=crop_image(file, Crop_size)
|
524 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
|
|
530 |
for file in tqdm(uploader.value, bar_format=' |{bar:15}| {n_fmt}/{total_fmt} Uploaded'):
|
531 |
filename = file['name']
|
532 |
img = Image.open(io.BytesIO(file['content']))
|
533 |
+
img=img.convert("RGB")
|
534 |
extension = filename.split(".")[-1]
|
535 |
identifier=filename.split(".")[0]
|
536 |
|
537 |
if extension.upper()=="JPG" or extension.upper()=="jpg":
|
|
|
538 |
img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
|
539 |
else:
|
540 |
img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
|
541 |
+
|
542 |
+
if ren:
|
543 |
+
i=0
|
544 |
+
for filename in tqdm(os.listdir(INSTANCE_DIR), bar_format=' |{bar:15}| {n_fmt}/{total_fmt} Renamed'):
|
545 |
+
extension = filename.split(".")[-1]
|
546 |
+
identifier=filename.split(".")[0]
|
547 |
+
new_path_with_file = os.path.join(INSTANCE_DIR, "conceptimagedb"+str(i)+"."+extension)
|
548 |
+
call('mv "'+os.path.join(INSTANCE_DIR,filename)+'" "'+new_path_with_file+'"', shell=True)
|
549 |
+
i=i+1
|
550 |
|
551 |
os.chdir(INSTANCE_DIR)
|
552 |
call('find . -name "* *" -type f | rename ' "'s/ /-/g'", shell=True)
|
|
|
556 |
|
557 |
|
558 |
|
559 |
+
|
560 |
def caption(CAPTIONS_DIR, INSTANCE_DIR):
|
561 |
|
562 |
paths=""
|