Skip to content

Commit

Permalink
Change flaim image viewer to viu (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossturk authored Jan 25, 2025
1 parent 66ec0de commit 8ec33b9
Show file tree
Hide file tree
Showing 7 changed files with 372 additions and 242 deletions.
533 changes: 326 additions & 207 deletions flaim/.flox/env/manifest.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion flaim/.flox/env/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gum.pkg-path = "gum"
curl.pkg-path = "curl"
coreutils.pkg-path = "coreutils"
figlet.pkg-path = "toilet"
viu.pkg-path = "viu"

# Required for stdc linking
gcc-unwrapped.pkg-path = "gcc-unwrapped"
Expand Down Expand Up @@ -98,7 +99,6 @@ transformers
sentencepiece
bitsandbytes
protobuf
sixel
jupyterlab
ipywidgets
EOF
Expand Down
16 changes: 9 additions & 7 deletions flaim/blart/blart-flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

# grab some image tools
from PIL import Image
import sixel
from io import BytesIO
import sys
import gc

Expand All @@ -42,10 +40,15 @@

# draw images in the terminal
def draw(image):
buffer = BytesIO()
writer = sixel.SixelWriter()
image.save(buffer, format='png')
writer.draw(buffer)
import tempfile
import subprocess
import os
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file:
output_file = temp_file.name
image.save(output_file)

subprocess.run(['viu', output_file], check=True)
os.remove(output_file)

# set our device and nope out if we don't have either CUDA or Metal
if torch.cuda.is_available():
Expand Down Expand Up @@ -119,7 +122,6 @@ def draw(image):
protocomp.paste(im, (x_offset, -212))
x_offset += im.size[0]

# this requires a sixel terminal to do anything, sadly
draw(protocomp)
print("\n")

Expand Down
16 changes: 9 additions & 7 deletions flaim/blart/blart-proteus.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

# grab some image tools
from PIL import Image
import sixel
from io import BytesIO
import sys
import gc

Expand All @@ -37,10 +35,15 @@

# draw images in the terminal
def draw(image):
buffer = BytesIO()
writer = sixel.SixelWriter()
image.save(buffer, format='png')
writer.draw(buffer)
import tempfile
import subprocess
import os
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file:
output_file = temp_file.name
image.save(output_file)

subprocess.run(['viu', output_file], check=True)
os.remove(output_file)

# set our device and nope out if we don't have either CUDA or Metal
if torch.cuda.is_available():
Expand Down Expand Up @@ -123,7 +126,6 @@ def draw(image):
protocomp.paste(im, (x_offset, -212))
x_offset += im.size[0]

# this requires a sixel terminal to do anything, sadly
draw(protocomp)
print("\n")

Expand Down
16 changes: 9 additions & 7 deletions flaim/blart/blart-sd3.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

# grab some image tools
from PIL import Image
import sixel
from io import BytesIO
import sys
import gc

Expand All @@ -41,10 +39,15 @@

# draw images in the terminal
def draw(image):
buffer = BytesIO()
writer = sixel.SixelWriter()
image.save(buffer, format='png')
writer.draw(buffer)
import tempfile
import subprocess
import os
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file:
output_file = temp_file.name
image.save(output_file)

subprocess.run(['viu', output_file], check=True)
os.remove(output_file)

# set our device and nope out if we don't have either CUDA or Metal
if torch.cuda.is_available():
Expand Down Expand Up @@ -117,7 +120,6 @@ def draw(image):
protocomp.paste(im, (x_offset, -212))
x_offset += im.size[0]

# this requires a sixel terminal to do anything, sadly
draw(protocomp)
print("\n")

Expand Down
16 changes: 9 additions & 7 deletions flaim/blart/blart-sd35.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

# grab some image tools
from PIL import Image
from io import BytesIO
import sixel
import sys
import gc

Expand All @@ -44,10 +42,15 @@

# draw images in the terminal
def draw(image):
buffer = BytesIO()
writer = sixel.SixelWriter()
image.save(buffer, format='png')
writer.draw(buffer)
import tempfile
import subprocess
import os
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file:
output_file = temp_file.name
image.save(output_file)

subprocess.run(['viu', output_file], check=True)
os.remove(output_file)

# set our device and nope out if we don't have either CUDA or Metal
if torch.cuda.is_available():
Expand Down Expand Up @@ -153,7 +156,6 @@ def draw(image):
protocomp.paste(im, (x_offset, -212))
x_offset += im.size[0]

# this requires a sixel terminal to do anything, sadly
draw(protocomp)
print("\n")

Expand Down
15 changes: 9 additions & 6 deletions flaim/helpers/genimg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@

import sys
import torch
import sixel
from io import BytesIO
from diffusers import StableDiffusionPipeline
from diffusers import logging

def draw(image):
buffer = BytesIO()
writer = sixel.SixelWriter()
image.save(buffer, format='png')
writer.draw(buffer)
import tempfile
import subprocess
import os
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file:
output_file = temp_file.name
image.save(output_file)

subprocess.run(['viu', output_file], check=True)
os.remove(output_file)

logging.set_verbosity(50)
logging.disable_progress_bar()
Expand Down

0 comments on commit 8ec33b9

Please sign in to comment.