Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
CursedPrograms committed Jan 28, 2024
1 parent 7d8cdc5 commit 8131846
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Auto detect text files and perform LF normalization
* text=auto
*.md linguist-vendored=false
*.md linguist-generated=false
*.md linguist-documentation=false
*.md linguist-detectable=true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
psdenv/
output/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
1 change: 1 addition & 0 deletions link.bf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
++++++++++[>+>+++>+++++++>++++++++++<<<<-]>>>>-.++++++++++++++++++.---.+.--------------.-.<<+++++++++++++++.>>+.+++++++++.++++++.---------------.+++++++++++++.++.-------------------.++++++++.+++++.-.--------.+++++++++.++++++.<<+.>>-----------.+++++++++++.-----------------.+++++.<<.>>+.++++++.
81 changes: 81 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import sys
import os

def main():
print("SDXL-Turbo Model Card")
print("1. Text-to-image")
print("2. Image-to-image")

choice = input("Select an operation (1 or 2): ")

if choice == "1":
text_to_image_prompt()
elif choice == "2":
image_to_image_prompt()
else:
print("Invalid choice. Exiting.")
sys.exit()

def text_to_image_prompt():
print("Using SDXL-Turbo for Text-to-image:")
print("Make sure to install the required packages using:")
print("pip install diffusers transformers accelerate --upgrade")
print()

print("Sample prompt:")
prompt = input("Enter a text prompt: ")

text_to_image_code = f"""
from diffusers import AutoPipelineForText2Image
import torch
from PIL import Image
pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
pipe.to("cuda")
prompt = "{prompt}"
image = pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0]
image.save("output/output.jpg")
"""

print()
print("Generated code snippet:")
print(text_to_image_code)

exec(text_to_image_code)

def image_to_image_prompt():
print("Using SDXL-Turbo for Image-to-image:")
print("Make sure to install the required packages using:")
print("pip install diffusers transformers accelerate --upgrade")
print()

print("Sample prompt:")
prompt = input("Enter a text prompt: ")

image_to_image_code = f"""
from diffusers import AutoPipelineForImage2Image
from diffusers.utils import load_image
import torch
from PIL import Image
pipe = AutoPipelineForImage2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
pipe.to("cuda")
init_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png").resize((512, 512))
prompt = "{prompt}"
image = pipe(prompt, image=init_image, num_inference_steps=2, strength=0.5, guidance_scale=0.0).images[0]
image.save("output/output.jpg")
"""

print()
print("Generated code snippet:")
print(image_to_image_code)

exec(image_to_image_code)

if __name__ == "__main__":
main()
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
transformers==4.37.1
pillow==10.2.0

pip install diffusers transformers accelerate --upgrade
15 changes: 15 additions & 0 deletions run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@echo off

set "VENV_DIR=psdenv"

rem
if not exist "%VENV_DIR%" (
rem
python -m venv "%VENV_DIR%"
)

rem
call "%VENV_DIR%\Scripts\activate" && python main.py

rem
pause
3 changes: 3 additions & 0 deletions setup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
python -m venv psdenv
cmd /k ".\psdenv\Scripts\activate & python main.py"
1 change: 1 addition & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python main.py

0 comments on commit 8131846

Please sign in to comment.