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 Vision | |
import UIKit | |
import ImageIO | |
struct TitleEmbedding: Codable { | |
let fullNameCopy: String | |
let keyword: String | |
let embedding: [Float] | |
} |
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 Vision | |
import UIKit | |
import ImageIO | |
struct TitleEmbedding: Codable { | |
let fullNameCopy: String | |
let keyword: String | |
let embedding: [Float] | |
} |
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
// CoreMLProcessing.swift | |
private var statsEmbeddings: [StatEmbedding] = [] | |
private var titleEmbeddings: [TitleEmbedding] = [] | |
func loadCLIPModelAndEmbeddings() { | |
model = nil | |
statsEmbeddings = [] | |
titleEmbeddings = [] |
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 titles list with descriptions | |
titles = [] | |
with open("names.txt", "r", encoding="utf-8") as f: | |
for line in f: |
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: |
NewerOlder