Created
June 11, 2024 00:53
-
-
Save schwa/3bc8be57c7167b4dd411932e333e7052 to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// 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