Skip to content

Instantly share code, notes, and snippets.

@schwa
Created June 11, 2024 00:53
Show Gist options
  • Save schwa/3bc8be57c7167b4dd411932e333e7052 to your computer and use it in GitHub Desktop.
Save schwa/3bc8be57c7167b4dd411932e333e7052 to your computer and use it in GitHub Desktop.
//
// ContentView.swift
// HotOrNot
//
// Created by Jonathan Wight on 6/10/24.
//
import SwiftUI
import Vision
struct ContentView: View {
@State
var image: Image?
@State
var observation: ImageAestheticsScoresObservation?
var body: some View {
Color.white
.overlay(alignment: .bottom) {
if let observation {
VStack {
LabeledContent("Confidence", value: observation.confidence, format: .number)
LabeledContent("isUtility", value: String(describing: observation.isUtility))
LabeledContent("Score", value: observation.overallScore, format: .number)
}
.padding()
.foregroundColor(.cyan)
.background(.ultraThickMaterial)
.font(.title)
.padding()
}
}
.overlay {
image
}
.dropDestination(for: Image.self) { items, location in
self.image = items.first
guard let image else {
return false
}
guard let cgImage = ImageRenderer(content: image).cgImage else {
return false
}
Task {
let request = CalculateImageAestheticsScoresRequest()
self.observation = try! await request.perform(on: cgImage)
print(self.observation)
}
return true
}
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment