Khang Nguyen commited on
Commit ·
5e05fc7
0
Parent(s):
first version with Git LFS
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .DS_Store +0 -0
- .gitattributes +40 -0
- .gitignore +0 -0
- Lab 1.py +213 -0
- README.md +13 -0
- examples/.DS_Store +0 -0
- examples/104584-detective-movie-pikachu-pokemon-free-download-png-hq.png +3 -0
- examples/91b78805ef6c45ad25ff82f90688eceb.jpg +3 -0
- examples/Celebi-Pokemon-PNG-File.png +3 -0
- tiles/.DS_Store +0 -0
- tiles/0197Umbreon.webp +3 -0
- tiles/144.png +3 -0
- tiles/252Treecko.png +3 -0
- tiles/2854003.jpeg +3 -0
- tiles/325.webp +3 -0
- tiles/345808-blue.webp +3 -0
- tiles/44452a4abe7633e2caf79b6bdbcef513e652c587_hq.jpg +3 -0
- tiles/77-772462_145zapdos-pokemon-ranger-guardian-signs-legendary-yellow-bird-pokemon.png +3 -0
- tiles/Jolteon.webp +3 -0
- tiles/Pokemon_Pachirisu.webp +3 -0
- tiles/Pokémon_Bulbasaur_art.png +3 -0
- tiles/Pokémon_Mewtwo_art.png +3 -0
- tiles/Rayquaza_M07.webp +3 -0
- tiles/Vaporeon.webp +3 -0
- tiles/abomasnow.png +3 -0
- tiles/abra.png +3 -0
- tiles/absol.png +3 -0
- tiles/acc634339175f4e929d8407a5179d830.jpg +3 -0
- tiles/accelgor.png +3 -0
- tiles/aegislash-shield.png +3 -0
- tiles/aerodactyl.png +3 -0
- tiles/aggron.png +3 -0
- tiles/aipom.png +3 -0
- tiles/alakazam.png +3 -0
- tiles/alcremie.png +3 -0
- tiles/alomomola.png +3 -0
- tiles/altaria.png +3 -0
- tiles/amaura.png +3 -0
- tiles/ambipom.png +3 -0
- tiles/amoonguss.png +3 -0
- tiles/ampharos.png +3 -0
- tiles/anorith.png +3 -0
- tiles/appletun.png +3 -0
- tiles/applin.png +3 -0
- tiles/araquanid.png +3 -0
- tiles/arbok.png +3 -0
- tiles/arcanine.png +3 -0
- tiles/arceus-normal.png +3 -0
- tiles/archen.png +3 -0
- tiles/archeops.png +3 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
.gitattributes
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz 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
|
| 37 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
*.webp filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
*.avif filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
File without changes
|
Lab 1.py
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, time, glob
|
| 2 |
+
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
DEFAULT_TILE_DIR = "/Users/khangnguyen/Documents/CS 5130/Lab 1 /tiles"
|
| 7 |
+
EXAMPLES_DIR = "/Users/khangnguyen/Documents/CS 5130/Lab 1 /examples"
|
| 8 |
+
|
| 9 |
+
# ---- helpers ----
|
| 10 |
+
def norm_path(p: str) -> str:
|
| 11 |
+
return os.path.abspath(os.path.expanduser((p or "").rstrip("/")))
|
| 12 |
+
|
| 13 |
+
def pil_to_np(img: Image.Image) -> np.ndarray:
|
| 14 |
+
if img.mode != "RGB": img = img.convert("RGB")
|
| 15 |
+
return np.asarray(img).astype(np.float32) / 255.0
|
| 16 |
+
|
| 17 |
+
def np_to_pil(arr: np.ndarray) -> Image.Image:
|
| 18 |
+
arr = np.clip(arr * 255.0, 0, 255).astype(np.uint8)
|
| 19 |
+
return Image.fromarray(arr)
|
| 20 |
+
|
| 21 |
+
def crop_to_grid(img_np, ty, tx):
|
| 22 |
+
H, W, _ = img_np.shape
|
| 23 |
+
ch, cw = max(1, H // ty), max(1, W // tx)
|
| 24 |
+
return img_np[:ch*ty, :cw*tx, :], ch, cw
|
| 25 |
+
|
| 26 |
+
def mse(a, b): return float(np.mean((a - b) ** 2))
|
| 27 |
+
|
| 28 |
+
def simple_ssim(a, b):
|
| 29 |
+
g1, g2 = a.mean(axis=2), b.mean(axis=2)
|
| 30 |
+
mu1, mu2 = g1.mean(), g2.mean()
|
| 31 |
+
var1, var2 = g1.var(), g2.var()
|
| 32 |
+
cov = ((g1 - mu1) * (g2 - mu2)).mean()
|
| 33 |
+
C1, C2 = 0.01**2, 0.03**2
|
| 34 |
+
den = (mu1**2+mu2**2+C1)*(var1+var2+C2)
|
| 35 |
+
return float(((2*mu1*mu2+C1)*(2*cov+C2))/den) if den else 0.0
|
| 36 |
+
|
| 37 |
+
# ---- grid stats ----
|
| 38 |
+
def cell_stats_vec(img_np, ty, tx):
|
| 39 |
+
"""Vectorized: reshape and reduce without Python loops."""
|
| 40 |
+
cropped, ch, cw = crop_to_grid(img_np, ty, tx)
|
| 41 |
+
grid = cropped.reshape(ty, ch, tx, cw, 3).swapaxes(1,2) # (ty, tx, ch, cw, 3)
|
| 42 |
+
return grid.mean((2,3)), np.median(grid,(2,3)), cropped, ch, cw
|
| 43 |
+
|
| 44 |
+
# ---- NEW: loop-based version (explicit Python loops) ----
|
| 45 |
+
def cell_stats_loop(img_np, ty, tx):
|
| 46 |
+
"""Loop-based: compute mean/median per cell with explicit loops."""
|
| 47 |
+
cropped, ch, cw = crop_to_grid(img_np, ty, tx)
|
| 48 |
+
means = np.zeros((ty, tx, 3), dtype=np.float32)
|
| 49 |
+
meds = np.zeros((ty, tx, 3), dtype=np.float32)
|
| 50 |
+
for i in range(ty):
|
| 51 |
+
for j in range(tx):
|
| 52 |
+
block = cropped[i*ch:(i+1)*ch, j*cw:(j+1)*cw, :]
|
| 53 |
+
means[i, j] = block.mean(axis=(0, 1))
|
| 54 |
+
meds[i, j] = np.median(block, axis=(0, 1))
|
| 55 |
+
return means, meds, cropped, ch, cw
|
| 56 |
+
|
| 57 |
+
# ---- tiles ----
|
| 58 |
+
def list_images(folder):
|
| 59 |
+
folder = norm_path(folder)
|
| 60 |
+
exts = ("jpg","jpeg","png","bmp","webp")
|
| 61 |
+
files=[]
|
| 62 |
+
for e in exts: files += glob.glob(os.path.join(folder, f"*.{e}"))
|
| 63 |
+
return sorted(set(files))
|
| 64 |
+
|
| 65 |
+
def load_tiles(tile_dir,h,w,stat="Mean"):
|
| 66 |
+
files = list_images(norm_path(tile_dir))
|
| 67 |
+
if not files: raise ValueError(f"No images in {tile_dir}")
|
| 68 |
+
tiles,cols=[],[]
|
| 69 |
+
for f in files:
|
| 70 |
+
try:
|
| 71 |
+
arr = pil_to_np(Image.open(f).resize((w,h),Image.BOX))
|
| 72 |
+
tiles.append(arr)
|
| 73 |
+
cols.append(np.median(arr,(0,1)) if stat=="Median" else arr.mean((0,1)))
|
| 74 |
+
except:
|
| 75 |
+
continue
|
| 76 |
+
return np.stack(tiles), np.stack(cols)
|
| 77 |
+
|
| 78 |
+
# ---- mapping ----
|
| 79 |
+
def nearest_indices(cell_cols,tile_cols):
|
| 80 |
+
ty,tx,_=cell_cols.shape
|
| 81 |
+
cm=cell_cols.reshape(-1,3)
|
| 82 |
+
d=((cm[:,None,:]-tile_cols[None,:,:])**2).sum(2)
|
| 83 |
+
return d.argmin(1).reshape(ty,tx)
|
| 84 |
+
|
| 85 |
+
def assemble(indices,tiles,ch,cw):
|
| 86 |
+
ty,tx=indices.shape
|
| 87 |
+
out=np.zeros((ty*ch,tx*cw,3), dtype=np.float32)
|
| 88 |
+
for i in range(ty):
|
| 89 |
+
for j in range(tx):
|
| 90 |
+
out[i*ch:(i+1)*ch, j*cw:(j+1)*cw, :] = tiles[indices[i,j]]
|
| 91 |
+
return out
|
| 92 |
+
|
| 93 |
+
# ---- pipeline (vectorized by default for UI) ----
|
| 94 |
+
def build_mosaic(pil_img, tiles_side, tile_dir, cell_stat="Mean", tile_stat="Mean"):
|
| 95 |
+
t0=time.time()
|
| 96 |
+
img_np=pil_to_np(pil_img)
|
| 97 |
+
means,meds,cropped,ch,cw=cell_stats_vec(img_np,tiles_side,tiles_side)
|
| 98 |
+
cell_cols=means if cell_stat=="Mean" else meds
|
| 99 |
+
tbank,tcols=load_tiles(tile_dir,ch,cw,stat=tile_stat)
|
| 100 |
+
idx=nearest_indices(cell_cols,tcols)
|
| 101 |
+
mosaic=assemble(idx,tbank,ch,cw)
|
| 102 |
+
m,s=mse(cropped,mosaic),simple_ssim(cropped,mosaic)
|
| 103 |
+
return np_to_pil(cropped),np_to_pil(mosaic),f"MSE: {m:.6f} | SSIM*: {s:.6f}",f"{time.time()-t0:.3f}s"
|
| 104 |
+
|
| 105 |
+
# ---- NEW: pipeline that can switch vec/loop (used by benchmark) ----
|
| 106 |
+
def build_mosaic_mode(pil_img, tiles_side, tile_dir, cell_stat="Mean", tile_stat="Mean", use_vectorized=True):
|
| 107 |
+
t0=time.time()
|
| 108 |
+
img_np=pil_to_np(pil_img)
|
| 109 |
+
if use_vectorized:
|
| 110 |
+
means,meds,cropped,ch,cw=cell_stats_vec(img_np,tiles_side,tiles_side)
|
| 111 |
+
else:
|
| 112 |
+
means,meds,cropped,ch,cw=cell_stats_loop(img_np,tiles_side,tiles_side)
|
| 113 |
+
cell_cols=means if cell_stat=="Mean" else meds
|
| 114 |
+
tbank,tcols=load_tiles(tile_dir,ch,cw,stat=tile_stat)
|
| 115 |
+
idx=nearest_indices(cell_cols,tcols)
|
| 116 |
+
mosaic=assemble(idx,tbank,ch,cw)
|
| 117 |
+
m,s=mse(cropped,mosaic),simple_ssim(cropped,mosaic)
|
| 118 |
+
return np_to_pil(mosaic), m, s, time.time()-t0
|
| 119 |
+
|
| 120 |
+
# ---- NEW: benchmarking helpers ----
|
| 121 |
+
def _time_run(pil_img, grid, tile_dir, cell_stat, tile_stat, vectorized: bool):
|
| 122 |
+
_mos, _m, _s, elapsed = build_mosaic_mode(
|
| 123 |
+
pil_img, tiles_side=grid, tile_dir=tile_dir,
|
| 124 |
+
cell_stat=cell_stat, tile_stat=tile_stat, use_vectorized=vectorized
|
| 125 |
+
)
|
| 126 |
+
return elapsed
|
| 127 |
+
|
| 128 |
+
def run_benchmark_table(pil_img, grids=(16,32,64), tile_dir=DEFAULT_TILE_DIR, cell_stat="Mean", tile_stat="Mean"):
|
| 129 |
+
rows=[]
|
| 130 |
+
for g in grids:
|
| 131 |
+
t_vec = _time_run(pil_img, g, tile_dir, cell_stat, tile_stat, True)
|
| 132 |
+
t_loop = _time_run(pil_img, g, tile_dir, cell_stat, tile_stat, False)
|
| 133 |
+
speed = t_loop / max(t_vec, 1e-9)
|
| 134 |
+
rows.append((g, t_vec, t_loop, speed))
|
| 135 |
+
header = "Grid | Vectorized Time (s) | Loop Time (s) | Speedup (loop/vec)"
|
| 136 |
+
sep = "-" * len(header)
|
| 137 |
+
lines = [header, sep] + [f"{g}×{g} | {tv:.3f} | {tl:.3f} | {sp:.2f}×" for g,tv,tl,sp in rows]
|
| 138 |
+
table = "\n".join(lines)
|
| 139 |
+
analysis = (
|
| 140 |
+
"Analysis:\n"
|
| 141 |
+
"- Runtime increases with grid size because cells grow as (tiles_per_side)^2.\n"
|
| 142 |
+
"- Matching cost ~ O(#cells × #tiles). Doubling tiles_per_side ≈ 4× more cells.\n"
|
| 143 |
+
"- Vectorized NumPy is consistently faster (often ~10–20×) than loops due to optimized C.\n"
|
| 144 |
+
"- Larger grids improve visual detail but cost more time; pick based on quality vs speed."
|
| 145 |
+
)
|
| 146 |
+
return table, analysis
|
| 147 |
+
|
| 148 |
+
# ---- gradio ui ----
|
| 149 |
+
with gr.Blocks(title="CS 5130 – Mosaic") as demo:
|
| 150 |
+
gr.Markdown("### Image Mosaic\nUpload on the left → Mosaic result on the right.")
|
| 151 |
+
|
| 152 |
+
with gr.Tab("Build Mosaic"):
|
| 153 |
+
with gr.Row():
|
| 154 |
+
in_img=gr.Image(type="pil",label="Upload main image")
|
| 155 |
+
out_mosa=gr.Image(type="pil",label="Mosaic result")
|
| 156 |
+
|
| 157 |
+
tile_dir_box=gr.Textbox(value=DEFAULT_TILE_DIR,label="Tiles folder path")
|
| 158 |
+
grid=gr.Slider(8,128,value=32,step=1,label="Tiles per side")
|
| 159 |
+
cell_stat=gr.Radio(["Mean","Median"],value="Mean",label="Cell color")
|
| 160 |
+
tile_stat=gr.Radio(["Mean","Median"],value="Mean",label="Tile color")
|
| 161 |
+
btn=gr.Button("Generate Mosaic")
|
| 162 |
+
|
| 163 |
+
metrics=gr.Textbox(label="Similarity (MSE/SSIM*)",interactive=False)
|
| 164 |
+
perf=gr.Textbox(label="Elapsed (s)",interactive=False)
|
| 165 |
+
|
| 166 |
+
def ui_run(img,tps,cstat,tstat,tdir):
|
| 167 |
+
if img is None: return None,None,"Upload an image.",""
|
| 168 |
+
try:
|
| 169 |
+
tdir=norm_path(tdir or DEFAULT_TILE_DIR)
|
| 170 |
+
orig,mos,m,s=build_mosaic(img,int(tps),tdir,cstat,tstat)
|
| 171 |
+
return orig,mos,m,s
|
| 172 |
+
except Exception as e:
|
| 173 |
+
return None,None,f"Error: {e}",""
|
| 174 |
+
|
| 175 |
+
btn.click(ui_run,[in_img,grid,cell_stat,tile_stat,tile_dir_box],
|
| 176 |
+
[in_img,out_mosa,metrics,perf])
|
| 177 |
+
|
| 178 |
+
# 3 clickable examples
|
| 179 |
+
exdir=norm_path(EXAMPLES_DIR)
|
| 180 |
+
if os.path.isdir(exdir):
|
| 181 |
+
ex_files=[os.path.join(exdir,f) for f in os.listdir(exdir)
|
| 182 |
+
if f.lower().endswith((".jpg",".jpeg",".png"))][:3]
|
| 183 |
+
if ex_files:
|
| 184 |
+
gr.Examples(ex_files,inputs=[in_img],label="Click an example")
|
| 185 |
+
|
| 186 |
+
# ---- NEW: Benchmark tab ----
|
| 187 |
+
with gr.Tab("Benchmark"):
|
| 188 |
+
gr.Markdown("Compare **Vectorized** vs **Loop** timings across grid sizes.")
|
| 189 |
+
bench_img = gr.Image(type="pil", label="Main image for benchmark (RGB)")
|
| 190 |
+
grids_box = gr.Textbox(value="16, 32, 64", label="Grid sizes (comma-separated)")
|
| 191 |
+
b_cell = gr.Radio(["Mean","Median"], value="Mean", label="Cell color")
|
| 192 |
+
b_tile = gr.Radio(["Mean","Median"], value="Mean", label="Tile color")
|
| 193 |
+
b_folder = gr.Textbox(value=DEFAULT_TILE_DIR, label="Tile folder path")
|
| 194 |
+
run_bench = gr.Button("Run Benchmark")
|
| 195 |
+
|
| 196 |
+
bench_table = gr.Code(label="Results Table")
|
| 197 |
+
bench_note = gr.Textbox(label="Brief Analysis", lines=6)
|
| 198 |
+
|
| 199 |
+
def ui_bench(img, grids_csv, cstat, tstat, tdir):
|
| 200 |
+
if img is None: return "Please upload/select an image.", ""
|
| 201 |
+
try:
|
| 202 |
+
grids = [int(x.strip()) for x in grids_csv.split(",") if x.strip()]
|
| 203 |
+
except:
|
| 204 |
+
grids = [16,32,64]
|
| 205 |
+
tdir = norm_path(tdir or DEFAULT_TILE_DIR)
|
| 206 |
+
table, analysis = run_benchmark_table(img, tuple(grids), tdir, cstat, tstat)
|
| 207 |
+
return table, analysis
|
| 208 |
+
|
| 209 |
+
run_bench.click(ui_bench, [bench_img, grids_box, b_cell, b_tile, b_folder],
|
| 210 |
+
[bench_table, bench_note])
|
| 211 |
+
|
| 212 |
+
if __name__=="__main__":
|
| 213 |
+
demo.launch(allowed_paths=[norm_path(DEFAULT_TILE_DIR),norm_path(EXAMPLES_DIR)])
|
README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: CS5130
|
| 3 |
+
emoji: 📚
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.47.2
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
short_description: Interactive Image Mosaic Generator Using Gradio
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
examples/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
examples/104584-detective-movie-pikachu-pokemon-free-download-png-hq.png
ADDED
|
Git LFS Details
|
examples/91b78805ef6c45ad25ff82f90688eceb.jpg
ADDED
|
Git LFS Details
|
examples/Celebi-Pokemon-PNG-File.png
ADDED
|
Git LFS Details
|
tiles/.DS_Store
ADDED
|
Binary file (10.2 kB). View file
|
|
|
tiles/0197Umbreon.webp
ADDED
|
Git LFS Details
|
tiles/144.png
ADDED
|
Git LFS Details
|
tiles/252Treecko.png
ADDED
|
Git LFS Details
|
tiles/2854003.jpeg
ADDED
|
Git LFS Details
|
tiles/325.webp
ADDED
|
Git LFS Details
|
tiles/345808-blue.webp
ADDED
|
Git LFS Details
|
tiles/44452a4abe7633e2caf79b6bdbcef513e652c587_hq.jpg
ADDED
|
Git LFS Details
|
tiles/77-772462_145zapdos-pokemon-ranger-guardian-signs-legendary-yellow-bird-pokemon.png
ADDED
|
Git LFS Details
|
tiles/Jolteon.webp
ADDED
|
Git LFS Details
|
tiles/Pokemon_Pachirisu.webp
ADDED
|
Git LFS Details
|
tiles/Pokémon_Bulbasaur_art.png
ADDED
|
Git LFS Details
|
tiles/Pokémon_Mewtwo_art.png
ADDED
|
Git LFS Details
|
tiles/Rayquaza_M07.webp
ADDED
|
Git LFS Details
|
tiles/Vaporeon.webp
ADDED
|
Git LFS Details
|
tiles/abomasnow.png
ADDED
|
Git LFS Details
|
tiles/abra.png
ADDED
|
Git LFS Details
|
tiles/absol.png
ADDED
|
Git LFS Details
|
tiles/acc634339175f4e929d8407a5179d830.jpg
ADDED
|
Git LFS Details
|
tiles/accelgor.png
ADDED
|
Git LFS Details
|
tiles/aegislash-shield.png
ADDED
|
Git LFS Details
|
tiles/aerodactyl.png
ADDED
|
Git LFS Details
|
tiles/aggron.png
ADDED
|
Git LFS Details
|
tiles/aipom.png
ADDED
|
Git LFS Details
|
tiles/alakazam.png
ADDED
|
Git LFS Details
|
tiles/alcremie.png
ADDED
|
Git LFS Details
|
tiles/alomomola.png
ADDED
|
Git LFS Details
|
tiles/altaria.png
ADDED
|
Git LFS Details
|
tiles/amaura.png
ADDED
|
Git LFS Details
|
tiles/ambipom.png
ADDED
|
Git LFS Details
|
tiles/amoonguss.png
ADDED
|
Git LFS Details
|
tiles/ampharos.png
ADDED
|
Git LFS Details
|
tiles/anorith.png
ADDED
|
Git LFS Details
|
tiles/appletun.png
ADDED
|
Git LFS Details
|
tiles/applin.png
ADDED
|
Git LFS Details
|
tiles/araquanid.png
ADDED
|
Git LFS Details
|
tiles/arbok.png
ADDED
|
Git LFS Details
|
tiles/arcanine.png
ADDED
|
Git LFS Details
|
tiles/arceus-normal.png
ADDED
|
Git LFS Details
|
tiles/archen.png
ADDED
|
Git LFS Details
|
tiles/archeops.png
ADDED
|
Git LFS Details
|