This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
import numpy as np | |
import coremltools as ct | |
from transformers import CLIPTokenizer | |
# 1. Load labels | |
with open("stats.txt", "r") as f: | |
categories = [line.strip() for line in f if line.strip()] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
import numpy as np | |
import coremltools as ct | |
from transformers import CLIPTokenizer | |
# 1. Load labels | |
with open("stats.txt", "r") as f: | |
categories = [line.strip() for line in f if line.strip()] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Encode text and extract embeddings | |
for text in categories: | |
try: | |
# Tokenize text using CLIP tokenizer | |
encoded = tokenizer( | |
text, | |
return_tensors="np", | |
padding="max_length", | |
truncation=True, | |
max_length=77 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
import numpy as np | |
import coremltools as ct | |
from transformers import CLIPTokenizer | |
# 1. Load labels | |
with open("stats.txt", "r") as f: | |
categories = [line.strip() for line in f if line.strip()] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var baseImage: some View { | |
// ... | |
.if(showEffects && card.stats.rarity == .common) { $0.noStickerEffect() } | |
.if(showEffects && (card.stats.rarity == .rare || card.stats.rarity == .ultraRare)) { $0.circularFoilEffect() } | |
.if(showEffects && card.stats.rarity == .secretRare) { $0.metallicEffect() } | |
private var cutoutLayer: some View { | |
if showEffects { | |
// ... | |
.if((card.stats.rarity == .common || card.stats.rarity == .rare)) { $0.noStickerEffect() } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func checkRarity(from imageEmbedding: [Float]) -> Rarity { | |
guard let first = imageEmbedding.first else { | |
return .common | |
} | |
let decimalString = String(format: "%.12f", first) | |
if let lastDigitChar = decimalString.last, | |
let digit = Int(String(lastDigitChar)) { | |
switch digit { | |
case 9: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Rarity: String, Codable { | |
case common | |
case rare | |
case ultraRare | |
case secretRare | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Namespace private var namespace | |
// on the parent view | |
var body: some View { | |
NavigationStack { | |
ScrollView { | |
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 3), spacing: 12) { | |
ForEach(viewModel.cards) { card in | |
NavigationLink(value: card) { | |
collectionCard(card: card) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CardView(card: card, size: .small, showEffects: false) | |
.conditionalEffect( | |
.repeat(.wiggle(rate: .phaseLength(0.45)), | |
every: .seconds(2)), | |
condition: isWobbling) | |
.transition(.movingParts.poof) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CardGridView: View { | |
@Query(sort: \CardEntity.createdAt) private var cardEntities: [CardEntity] | |
var body: some View { | |
NavigationStack { | |
ScrollView { | |
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 3), spacing: 12) { | |
ForEach(cardEntities.compactMap { $0.toCard() }) { card in | |
CardView(card: card, size: .small, showEffects: false) | |
.onTapGesture { |