Michael Ramos commited on
Commit ·
9522910
1
Parent(s): 64b8712
Adding Train and Validation set
Browse files- .gitattributes +1 -0
- .gitignore +1 -0
- app.py +143 -0
- images/002.png +3 -0
- images/003-m.png +3 -0
- images/005.png +3 -0
- images/006.png +3 -0
- images/008.png +3 -0
- images/009.png +3 -0
- images/010.png +3 -0
- images/011.png +3 -0
- images/012.png +3 -0
- images/014.png +3 -0
- images/015.png +3 -0
- images/016.png +3 -0
- images/017.png +3 -0
- images/021.png +3 -0
- images/024.png +3 -0
- images/025.png +3 -0
- images/3D0040.png +3 -0
- images/Fig02_C.png +3 -0
- images/Fig02_F.png +3 -0
- images/Fig02_I.png +3 -0
- images/Fig06_C.png +3 -0
- images/Oct6_Page_04.png +3 -0
- images/Oct6_Page_05.png +3 -0
- images/Oct6_Page_06.png +3 -0
- images/Oct6_Page_12-1.png +3 -0
- images/Oct6_Page_12-2.png +3 -0
- images/Oct6_Page_13.png +3 -0
- images/Oct6_Page_18.png +3 -0
- images/Oct6_Page_23.png +3 -0
- images/Oct6_Page_25.png +3 -0
- images/Oct6_Page_29.png +3 -0
- images/Oct6_Page_32-1.png +3 -0
- images/Oct6_Page_32-2.png +3 -0
- images/Oct6_Page_33.png +3 -0
- requirements.txt +80 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
spc
|
app.py
ADDED
|
@@ -0,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 9 |
+
|
| 10 |
+
from PIL import Image
|
| 11 |
+
import numpy as np
|
| 12 |
+
import gradio as gr
|
| 13 |
+
import psutil
|
| 14 |
+
import time
|
| 15 |
+
import math
|
| 16 |
+
|
| 17 |
+
SAFETY_CHECKER = os.environ.get("SAFETY_CHECKER", None)
|
| 18 |
+
TORCH_COMPILE = os.environ.get("TORCH_COMPILE", None)
|
| 19 |
+
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 20 |
+
# check if MPS is available OSX only M1/M2/M3 chips
|
| 21 |
+
mps_available = hasattr(torch.backends, "mps") and torch.backends.mps.is_available()
|
| 22 |
+
xpu_available = hasattr(torch, "xpu") and torch.xpu.is_available()
|
| 23 |
+
device = torch.device(
|
| 24 |
+
"cuda" if torch.cuda.is_available() else "xpu" if xpu_available else "cpu"
|
| 25 |
+
)
|
| 26 |
+
torch_device = device
|
| 27 |
+
torch_dtype = torch.float16
|
| 28 |
+
|
| 29 |
+
print(f"SAFETY_CHECKER: {SAFETY_CHECKER}")
|
| 30 |
+
print(f"TORCH_COMPILE: {TORCH_COMPILE}")
|
| 31 |
+
print(f"device: {device}")
|
| 32 |
+
|
| 33 |
+
if mps_available:
|
| 34 |
+
device = torch.device("mps")
|
| 35 |
+
torch_device = "cpu"
|
| 36 |
+
torch_dtype = torch.float32
|
| 37 |
+
|
| 38 |
+
if SAFETY_CHECKER == "True":
|
| 39 |
+
i2i_pipe = AutoPipelineForImage2Image.from_pretrained(
|
| 40 |
+
"stabilityai/sdxl-turbo",
|
| 41 |
+
torch_dtype=torch_dtype,
|
| 42 |
+
variant="fp16" if torch_dtype == torch.float16 else "fp32",
|
| 43 |
+
)
|
| 44 |
+
t2i_pipe = AutoPipelineForText2Image.from_pretrained(
|
| 45 |
+
"stabilityai/sdxl-turbo",
|
| 46 |
+
torch_dtype=torch_dtype,
|
| 47 |
+
variant="fp16" if torch_dtype == torch.float16 else "fp32",
|
| 48 |
+
)
|
| 49 |
+
else:
|
| 50 |
+
i2i_pipe = AutoPipelineForImage2Image.from_pretrained(
|
| 51 |
+
"stabilityai/sdxl-turbo",
|
| 52 |
+
safety_checker=None,
|
| 53 |
+
torch_dtype=torch_dtype,
|
| 54 |
+
variant="fp16" if torch_dtype == torch.float16 else "fp32",
|
| 55 |
+
)
|
| 56 |
+
t2i_pipe = AutoPipelineForText2Image.from_pretrained(
|
| 57 |
+
"stabilityai/sdxl-turbo",
|
| 58 |
+
safety_checker=None,
|
| 59 |
+
torch_dtype=torch_dtype,
|
| 60 |
+
variant="fp16" if torch_dtype == torch.float16 else "fp32",
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
t2i_pipe.to(device=torch_device, dtype=torch_dtype).to(device)
|
| 64 |
+
t2i_pipe.set_progress_bar_config(disable=True)
|
| 65 |
+
i2i_pipe.to(device=torch_device, dtype=torch_dtype).to(device)
|
| 66 |
+
i2i_pipe.set_progress_bar_config(disable=True)
|
| 67 |
+
|
| 68 |
+
def resize_crop(image, size=512):
|
| 69 |
+
image = image.convert("RGB")
|
| 70 |
+
w, h = image.size
|
| 71 |
+
image = image.resize((size, int(size * (h / w))), Image.BICUBIC)
|
| 72 |
+
return image
|
| 73 |
+
|
| 74 |
+
# Global variable to store the selected image index
|
| 75 |
+
selected_image_index = None
|
| 76 |
+
|
| 77 |
+
# Load images from the 'images' folder
|
| 78 |
+
image_folder = 'images'
|
| 79 |
+
images = [Image.open(os.path.join(image_folder, img)) for img in sorted(os.listdir(image_folder)) if img.endswith(('.png', '.jpg', '.jpeg'))]
|
| 80 |
+
|
| 81 |
+
# Ensure that there are 34 images
|
| 82 |
+
assert len(images) == 34, "There should be exactly 34 images in the 'images' folder."
|
| 83 |
+
|
| 84 |
+
# Function to handle image selection
|
| 85 |
+
async def select_fn(data: gr.SelectData, prompt: str):
|
| 86 |
+
global selected_image_index
|
| 87 |
+
selected_image_index = data.index
|
| 88 |
+
return await predict(prompt)
|
| 89 |
+
|
| 90 |
+
async def predict(prompt):
|
| 91 |
+
global selected_image_index
|
| 92 |
+
strength = 0.49999999999999999
|
| 93 |
+
steps = 2
|
| 94 |
+
if selected_image_index is not None:
|
| 95 |
+
init_image = images[selected_image_index]
|
| 96 |
+
init_image = resize_crop(init_image)
|
| 97 |
+
generator = torch.manual_seed(123123)
|
| 98 |
+
last_time = time.time()
|
| 99 |
+
|
| 100 |
+
if int(steps * strength) < 1:
|
| 101 |
+
steps = math.ceil(1 / max(0.10, strength))
|
| 102 |
+
|
| 103 |
+
results = i2i_pipe(
|
| 104 |
+
prompt=prompt,
|
| 105 |
+
image=init_image,
|
| 106 |
+
generator=generator,
|
| 107 |
+
num_inference_steps=steps,
|
| 108 |
+
guidance_scale=0.0,
|
| 109 |
+
strength=strength,
|
| 110 |
+
width=512,
|
| 111 |
+
height=512,
|
| 112 |
+
output_type="pil",
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
print(f"Pipe took {time.time() - last_time} seconds")
|
| 116 |
+
nsfw_content_detected = (
|
| 117 |
+
results.nsfw_content_detected[0]
|
| 118 |
+
if "nsfw_content_detected" in results
|
| 119 |
+
else False
|
| 120 |
+
)
|
| 121 |
+
if nsfw_content_detected:
|
| 122 |
+
gr.Warning("NSFW content detected.")
|
| 123 |
+
return Image.new("RGB", (512, 512))
|
| 124 |
+
return results.images[0]
|
| 125 |
+
|
| 126 |
+
# Create the Gradio interface
|
| 127 |
+
with gr.Blocks() as app:
|
| 128 |
+
with gr.Row():
|
| 129 |
+
with gr.Column():
|
| 130 |
+
prompt = gr.Textbox(label="I see...")
|
| 131 |
+
image_gallery = gr.Gallery(value=images, columns=4) # Adjust number of columns as needed
|
| 132 |
+
with gr.Column():
|
| 133 |
+
output = gr.Image(label="Generation")
|
| 134 |
+
|
| 135 |
+
button = gr.Button("Rorschachify!")
|
| 136 |
+
|
| 137 |
+
image_gallery.select(select_fn, inputs=[prompt], outputs=output, show_progress=False)
|
| 138 |
+
button.click(fn=predict, inputs=[prompt], outputs=output, show_progress=False)
|
| 139 |
+
prompt.change(fn=predict, inputs=[prompt], outputs=output, show_progress=False)
|
| 140 |
+
|
| 141 |
+
# Run the app
|
| 142 |
+
app.queue()
|
| 143 |
+
app.launch()
|
images/002.png
ADDED
|
Git LFS Details
|
images/003-m.png
ADDED
|
Git LFS Details
|
images/005.png
ADDED
|
Git LFS Details
|
images/006.png
ADDED
|
Git LFS Details
|
images/008.png
ADDED
|
Git LFS Details
|
images/009.png
ADDED
|
Git LFS Details
|
images/010.png
ADDED
|
Git LFS Details
|
images/011.png
ADDED
|
Git LFS Details
|
images/012.png
ADDED
|
Git LFS Details
|
images/014.png
ADDED
|
Git LFS Details
|
images/015.png
ADDED
|
Git LFS Details
|
images/016.png
ADDED
|
Git LFS Details
|
images/017.png
ADDED
|
Git LFS Details
|
images/021.png
ADDED
|
Git LFS Details
|
images/024.png
ADDED
|
Git LFS Details
|
images/025.png
ADDED
|
Git LFS Details
|
images/3D0040.png
ADDED
|
Git LFS Details
|
images/Fig02_C.png
ADDED
|
Git LFS Details
|
images/Fig02_F.png
ADDED
|
Git LFS Details
|
images/Fig02_I.png
ADDED
|
Git LFS Details
|
images/Fig06_C.png
ADDED
|
Git LFS Details
|
images/Oct6_Page_04.png
ADDED
|
Git LFS Details
|
images/Oct6_Page_05.png
ADDED
|
Git LFS Details
|
images/Oct6_Page_06.png
ADDED
|
Git LFS Details
|
images/Oct6_Page_12-1.png
ADDED
|
Git LFS Details
|
images/Oct6_Page_12-2.png
ADDED
|
Git LFS Details
|
images/Oct6_Page_13.png
ADDED
|
Git LFS Details
|
images/Oct6_Page_18.png
ADDED
|
Git LFS Details
|
images/Oct6_Page_23.png
ADDED
|
Git LFS Details
|
images/Oct6_Page_25.png
ADDED
|
Git LFS Details
|
images/Oct6_Page_29.png
ADDED
|
Git LFS Details
|
images/Oct6_Page_32-1.png
ADDED
|
Git LFS Details
|
images/Oct6_Page_32-2.png
ADDED
|
Git LFS Details
|
images/Oct6_Page_33.png
ADDED
|
Git LFS Details
|
requirements.txt
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
accelerate==0.26.1
|
| 2 |
+
aiofiles==23.2.1
|
| 3 |
+
altair==5.2.0
|
| 4 |
+
annotated-types==0.6.0
|
| 5 |
+
anyio==4.2.0
|
| 6 |
+
attrs==23.2.0
|
| 7 |
+
certifi==2023.11.17
|
| 8 |
+
charset-normalizer==3.3.2
|
| 9 |
+
click==8.1.7
|
| 10 |
+
colorama==0.4.6
|
| 11 |
+
contourpy==1.2.0
|
| 12 |
+
cycler==0.12.1
|
| 13 |
+
diffusers==0.25.1
|
| 14 |
+
fastapi==0.109.0
|
| 15 |
+
ffmpy==0.3.1
|
| 16 |
+
filelock==3.13.1
|
| 17 |
+
fonttools==4.47.2
|
| 18 |
+
fsspec==2023.12.2
|
| 19 |
+
gradio==4.15.0
|
| 20 |
+
gradio_client==0.8.1
|
| 21 |
+
h11==0.14.0
|
| 22 |
+
httpcore==1.0.2
|
| 23 |
+
httpx==0.26.0
|
| 24 |
+
huggingface-hub==0.20.3
|
| 25 |
+
idna==3.6
|
| 26 |
+
importlib-metadata==7.0.1
|
| 27 |
+
importlib-resources==6.1.1
|
| 28 |
+
Jinja2==3.1.3
|
| 29 |
+
jsonschema==4.21.1
|
| 30 |
+
jsonschema-specifications==2023.12.1
|
| 31 |
+
kiwisolver==1.4.5
|
| 32 |
+
markdown-it-py==3.0.0
|
| 33 |
+
MarkupSafe==2.1.4
|
| 34 |
+
matplotlib==3.8.2
|
| 35 |
+
mdurl==0.1.2
|
| 36 |
+
mpmath==1.3.0
|
| 37 |
+
networkx==3.0
|
| 38 |
+
numpy==1.26.3
|
| 39 |
+
orjson==3.9.12
|
| 40 |
+
packaging==23.2
|
| 41 |
+
pandas==2.2.0
|
| 42 |
+
pillow==10.2.0
|
| 43 |
+
psutil==5.9.8
|
| 44 |
+
pydantic==2.5.3
|
| 45 |
+
pydantic_core==2.14.6
|
| 46 |
+
pydub==0.25.1
|
| 47 |
+
Pygments==2.17.2
|
| 48 |
+
pyparsing==3.1.1
|
| 49 |
+
python-dateutil==2.8.2
|
| 50 |
+
python-multipart==0.0.6
|
| 51 |
+
pytz==2023.3.post1
|
| 52 |
+
PyYAML==6.0.1
|
| 53 |
+
referencing==0.32.1
|
| 54 |
+
regex==2023.12.25
|
| 55 |
+
requests==2.31.0
|
| 56 |
+
rich==13.7.0
|
| 57 |
+
rpds-py==0.17.1
|
| 58 |
+
ruff==0.1.14
|
| 59 |
+
safetensors==0.4.2
|
| 60 |
+
semantic-version==2.10.0
|
| 61 |
+
shellingham==1.5.4
|
| 62 |
+
six==1.16.0
|
| 63 |
+
sniffio==1.3.0
|
| 64 |
+
starlette==0.35.1
|
| 65 |
+
sympy==1.12
|
| 66 |
+
tokenizers==0.15.1
|
| 67 |
+
tomlkit==0.12.0
|
| 68 |
+
toolz==0.12.1
|
| 69 |
+
torch==2.1.2+cu118
|
| 70 |
+
torchaudio==2.1.2+cu118
|
| 71 |
+
torchvision==0.16.2+cu118
|
| 72 |
+
tqdm==4.66.1
|
| 73 |
+
transformers==4.37.0
|
| 74 |
+
typer==0.9.0
|
| 75 |
+
typing_extensions==4.9.0
|
| 76 |
+
tzdata==2023.4
|
| 77 |
+
urllib3==2.1.0
|
| 78 |
+
uvicorn==0.27.0
|
| 79 |
+
websockets==11.0.3
|
| 80 |
+
zipp==3.17.0
|