Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

aestehtics changes

laurenspriem68f35afea89a
diff --git a/mobile/apps/photos/lib/services/wrapped/candidate_builders.dart b/mobile/apps/photos/lib/services/wrapped/candidate_builders.dart
index 6aaa52102f..f56e367198 100644
--- a/mobile/apps/photos/lib/services/wrapped/candidate_builders.dart
+++ b/mobile/apps/photos/lib/services/wrapped/candidate_builders.dart
@@ -1,9 +1,11 @@
import "dart:math" as math;
+import "dart:typed_data";
import "package:flutter/foundation.dart" show immutable;
import "package:intl/intl.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
+import "package:photos/services/machine_learning/face_ml/face_filtering/face_filtering_constants.dart";
import "package:photos/services/wrapped/models.dart";
import "package:photos/utils/standalone/data.dart";
@@ -22,13 +24,16 @@ class WrappedEngineContext {
required this.now,
required List<EnteFile> files,
WrappedPeopleContext? people,
+ WrappedAestheticsContext? aesthetics,
}) : files = List<EnteFile>.unmodifiable(files),
- people = people ?? WrappedPeopleContext.empty();
+ people = people ?? WrappedPeopleContext.empty(),
+ aesthetics = aesthetics ?? WrappedAestheticsContext.empty();
final int year;
final DateTime now;
final List<EnteFile> files;
final WrappedPeopleContext people;
+ final WrappedAestheticsContext aesthetics;
}
/// Contract for producing Wrapped candidate cards for a specific domain.
diff --git a/mobile/apps/photos/lib/services/wrapped/models.dart b/mobile/apps/photos/lib/services/wrapped/models.dart
index 36485b1ce2..e46bded073 100644
--- a/mobile/apps/photos/lib/services/wrapped/models.dart
+++ b/mobile/apps/photos/lib/services/wrapped/models.dart
@@ -75,6 +75,94 @@ class WrappedPeopleContext {
}
}
+@immutable
+class WrappedAestheticsContext {
+ WrappedAestheticsContext({
+ required Map<int, List<double>> clipEmbeddings,
+ required Map<String, List<double>> textEmbeddings,
+ }) : clipEmbeddings =
+ Map<int, List<double>>.unmodifiable(_dedupeLists(clipEmbeddings)),
+ textEmbeddings = Map<String, List<double>>.unmodifiable(
+ _dedupeLists(textEmbeddings),
+ );
+
+ factory WrappedAestheticsContext.empty() {
+ return WrappedAestheticsContext(
+ clipEmbeddings: const <int, List<double>>{},
+ textEmbeddings: const <String, List<double>>{},
+ );
+ }
+
+ final Map<int, List<double>> clipEmbeddings;
+ final Map<String, List<double>> textEmbeddings;
+
+ bool get hasEmbeddings => clipEmbeddings.isNotEmpty;
+
+ Map<String, Object?> toJson() {
+ return <String, Object?>{
+ "clipEmbeddings": clipEmbeddings.map(
+ (int key, List<double> value) => MapEntry(
+ key.toString(),
+ value,
+ ),
+ ),
+ "textEmbeddings": textEmbeddings,
+ };
+ }
+
+ static WrappedAestheticsContext fromJson(Map<String, Object?> json) {
+ final Map<String, Object?> rawClip =
+ (json["clipEmbeddings"] as Map?)?.cast<String, Object?>() ??
+ <String, Object?>{};
+ final Map<int, List<double>> clipEmbeddings = <int, List<double>>{
+ for (final MapEntry<String, Object?> entry in rawClip.entries)
+ int.tryParse(entry.key) ?? 0: _castToDoubleList(entry.value),
+ }..removeWhere((int key, List<double> value) => key <= 0 || value.isEmpty);
+
+ final Map<String, Object?> rawText =
+ (json["textEmbeddings"] as Map?)?.cast<String, Object?>() ??
+ <String, Object?>{};
+ final Map<String, List<double>> textEmbeddings = <String, List<double>>{
+ for (final MapEntry<String, Object?> entry in rawText.entries)
+ entry.key: _castToDoubleList(entry.value),
+ }..removeWhere((String key, List<double> value) => value.isEmpty);
+
+ if (clipEmbeddings.isEmpty && textEmbeddings.isEmpty) {
+ return WrappedAestheticsContext.empty();
+ }
+
+ return WrappedAestheticsContext(
+ clipEmbeddings: clipEmbeddings,
+ textEmbeddings: textEmbeddings,
+ );
+ }
+
+ static Map<K, List<double>> _dedupeLists<K>(
+ Map<K, List<double>> source,
+ ) {
+ final Map<K, List<double>> result = <K, List<double>>{};
+ source.forEach((K key, List<double> value) {
+ result[key] = List<double>.from(value, growable: false);
+ });
+ return result;
+ }
+
+ static List<double> _castToDoubleList(Object? source) {
+ if (source is List<double>) {
+ return List<double>.from(source, growable: false);
+ }
+ if (source is List) {
+ return List<double>.from(
+ source.map((Object? e) {
+ if (e is num) return e.toDouble();
+ return 0.0;
+ }),
+ );
+ }
+ return const <double>[];
+ }
+}
+
@immutable
class WrappedPeopleFile {
WrappedPeopleFile({
@@ -347,7 +435,7 @@ enum WrappedCardType {
thenAndNow,
yearInColor,
monochrome,
- panoramas,
+ blurryFaces,
biggestShot,
top9Wow,
favorites,
diff --git a/mobile/apps/photos/lib/services/wrapped/wrapped_engine.dart b/mobile/apps/photos/lib/services/wrapped/wrapped_engine.dart
index 9eae37492d..d8cec44a8a 100644
--- a/mobile/apps/photos/lib/services/wrapped/wrapped_engine.dart
+++ b/mobile/apps/photos/lib/services/wrapped/wrapped_engine.dart
@@ -5,9 +5,11 @@ import "package:photos/models/file/extensions/file_props.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/ml/face/face_with_embedding.dart";
import "package:photos/models/ml/face/person.dart";
+import "package:photos/models/ml/vector.dart";
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
import "package:photos/services/machine_learning/ml_result.dart";
import "package:photos/services/search_service.dart";
+import "package:photos/services/text_embeddings_cache_service.dart";
import "package:photos/services/wrapped/candidate_builders.dart";
import "package:photos/services/wrapped/models.dart";
@@ -33,6 +35,11 @@ class WrappedEngine {
yearFiles: collected.yearFiles,
fileByUploadedId: collected.fileByUploadedId,
);
+ final WrappedAestheticsContext aestheticsContext =
+ await _collectAestheticsContext(
+ year: year,
+ yearFiles: collected.yearFiles,
+ );
return await Computer.shared().compute(
_wrappedComputeIsolate,
@@ -41,6 +48,7 @@ class WrappedEngine {
"now": now,
"files": collected.yearFiles,
"people": peopleContext.toJson(),
+ "aesthetics": aestheticsContext.toJson(),
},
taskName: "wrapped_compute_$year",
) as WrappedResult;
@@ -231,6 +239,67 @@ class WrappedEngine {
personFirstCaptureMicros: personFirstCaptureMicros,
);
}
+
+ static Future<WrappedAestheticsContext> _collectAestheticsContext({
+ required int year,
+ required List<EnteFile> yearFiles,
+ }) async {
+ if (yearFiles.isEmpty) {
+ return WrappedAestheticsContext.empty();
+ }
+
+ final Set<int> yearFileIDs = <int>{
+ for (final EnteFile file in yearFiles)
+ if (file.uploadedFileID != null) file.uploadedFileID!,
+ };
+ if (yearFileIDs.isEmpty) {
+ return WrappedAestheticsContext.empty();
+ }
+
+ final Map<int, List<double>> clipEmbeddings = <int, List<double>>{};
+ try {
+ final List<EmbeddingVector> vectors =
+ await MLDataDB.instance.getAllClipVectors();
+ for (final EmbeddingVector vector in vectors) {
+ final int fileID = vector.fileID;
+ if (!yearFileIDs.contains(fileID) || vector.isEmpty) {
+ continue;
+ }
+ clipEmbeddings[fileID] = vector.vector.toList(growable: false);
+ }
+ } catch (error, stackTrace) {
+ _engineLogger.warning(
+ "Failed to collect CLIP embeddings for Wrapped $year",
+ error,
+ stackTrace,
+ );
+ }
+
+ if (clipEmbeddings.isEmpty) {
+ return WrappedAestheticsContext.empty();
+ }
+
+ final Set<String> queries = AestheticsCandidateBuilder.requiredTextQueries;
+ final Map<String, List<double>> textEmbeddings = <String, List<double>>{};
+ for (final String query in queries) {
+ try {
+ final List<double> embedding =
+ await TextEmbeddingsCacheService.instance.getEmbedding(query);
+ textEmbeddings[query] = List<double>.from(embedding, growable: false);
+ } catch (error, stackTrace) {
+ _engineLogger.warning(
+ "Failed to compute text embedding for Wrapped query \"$query\"",
+ error,
+ stackTrace,
+ );
+ }
+ }
+
+ return WrappedAestheticsContext(
+ clipEmbeddings: clipEmbeddings,
+ textEmbeddings: textEmbeddings,
+ );
+ }
}
Future<WrappedResult> _wrappedComputeIsolate(
@@ -243,6 +312,11 @@ Future<WrappedResult> _wrappedComputeIsolate(
final Map<String, Object?> peopleRaw =
(args["people"] as Map?)?.cast<String, Object?>() ?? <String, Object?>{};
final WrappedPeopleContext people = WrappedPeopleContext.fromJson(peopleRaw);
+ final Map<String, Object?> aestheticsRaw =
+ (args["aesthetics"] as Map?)?.cast<String, Object?>() ??
+ <String, Object?>{};
+ final WrappedAestheticsContext aesthetics =
+ WrappedAestheticsContext.fromJson(aestheticsRaw);
_computeLogger.fine(
"Wrapped compute isolate running for $year with ${files.length} media items",
@@ -253,6 +327,7 @@ Future<WrappedResult> _wrappedComputeIsolate(
now: now,
files: files,
people: people,
+ aesthetics: aesthetics,
);
final List<WrappedCard> cards = <WrappedCard>[];
for (final WrappedCandidateBuilder builder in wrappedCandidateBuilders) {
diff --git a/mobile/apps/photos/lib/ui/wrapped/cards/aesthetics_card_content.dart b/mobile/apps/photos/lib/ui/wrapped/cards/aesthetics_card_content.dart
index 2c3773b3b6..dedbb5b4a3 100644
--- a/mobile/apps/photos/lib/ui/wrapped/cards/aesthetics_card_content.dart
+++ b/mobile/apps/photos/lib/ui/wrapped/cards/aesthetics_card_content.dart
@@ -5,5 +5,342 @@ Widget? buildAestheticsCardContent(
EnteColorScheme colorScheme,
EnteTextTheme textTheme,
) {
- return null;
+ switch (card.type) {
+ case WrappedCardType.blurryFaces:
+ return _BlurryFacesCardContent(
+ card: card,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ );
+ case WrappedCardType.yearInColor:
+ return _YearInColorCardContent(
+ card: card,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ );
+ case WrappedCardType.monochrome:
+ return _MonochromeCardContent(
+ card: card,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ );
+ case WrappedCardType.top9Wow:
+ return _TopWowCardContent(
+ card: card,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ );
+ default:
+ return null;
+ }
+}
+
+class _BlurryFacesCardContent extends StatelessWidget {
+ const _BlurryFacesCardContent({
+ required this.card,
+ required this.colorScheme,
+ required this.textTheme,
+ });
+
+ final WrappedCard card;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+
+ @override
+ Widget build(BuildContext context) {
+ final List<String> chips = _stringListFromMeta(card.meta, "detailChips");
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ _HeroMediaCollage(
+ media: card.media,
+ colorScheme: colorScheme,
+ ),
+ const SizedBox(height: 24),
+ Text(
+ card.title,
+ style: textTheme.h2Bold,
+ ),
+ if (card.subtitle != null && card.subtitle!.isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.only(top: 12),
+ child: Text(
+ card.subtitle!,
+ style: textTheme.bodyMuted,
+ ),
+ ),
+ if (chips.isNotEmpty) ...[
+ const SizedBox(height: 20),
+ _DetailChips(
+ chips: chips,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ ),
+ ],
+ const Spacer(),
+ ],
+ );
+ }
+}
+
+class _YearInColorCardContent extends StatelessWidget {
+ const _YearInColorCardContent({
+ required this.card,
+ required this.colorScheme,
+ required this.textTheme,
+ });
+
+ final WrappedCard card;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+
+ @override
+ Widget build(BuildContext context) {
+ final List<String> detailChips = _stringListFromMeta(
+ card.meta,
+ "detailChips",
+ );
+ final List<_PaletteEntry> palette = _paletteEntriesFromMeta(card.meta);
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ _MediaGrid(
+ media: card.media.take(6).toList(growable: false),
+ colorScheme: colorScheme,
+ ),
+ const SizedBox(height: 24),
+ Text(
+ card.title,
+ style: textTheme.h2Bold,
+ ),
+ if (card.subtitle != null && card.subtitle!.isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.only(top: 12),
+ child: Text(
+ card.subtitle!,
+ style: textTheme.bodyMuted,
+ ),
+ ),
+ if (palette.isNotEmpty) ...[
+ const SizedBox(height: 18),
+ _PaletteSwatches(
+ entries: palette,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ ),
+ ],
+ if (detailChips.isNotEmpty) ...[
+ const SizedBox(height: 20),
+ _DetailChips(
+ chips: detailChips,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ ),
+ ],
+ const Spacer(),
+ ],
+ );
+ }
+}
+
+class _MonochromeCardContent extends StatelessWidget {
+ const _MonochromeCardContent({
+ required this.card,
+ required this.colorScheme,
+ required this.textTheme,
+ });
+
+ final WrappedCard card;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+
+ @override
+ Widget build(BuildContext context) {
+ final List<String> chips = _stringListFromMeta(card.meta, "detailChips");
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ card.title,
+ style: textTheme.h2Bold,
+ ),
+ if (card.subtitle != null && card.subtitle!.isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.only(top: 12),
+ child: Text(
+ card.subtitle!,
+ style: textTheme.bodyMuted,
+ ),
+ ),
+ const SizedBox(height: 20),
+ _MediaGrid(
+ media: card.media.take(6).toList(growable: false),
+ colorScheme: colorScheme,
+ ),
+ if (chips.isNotEmpty) ...[
+ const SizedBox(height: 18),
+ _DetailChips(
+ chips: chips,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ ),
+ ],
+ const Spacer(),
+ ],
+ );
+ }
+}
+
+class _TopWowCardContent extends StatelessWidget {
+ const _TopWowCardContent({
+ required this.card,
+ required this.colorScheme,
+ required this.textTheme,
+ });
+
+ final WrappedCard card;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+
+ @override
+ Widget build(BuildContext context) {
+ final List<String> chips = _stringListFromMeta(card.meta, "detailChips");
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ card.title,
+ style: textTheme.h2Bold,
+ ),
+ if (card.subtitle != null && card.subtitle!.isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.only(top: 12),
+ child: Text(
+ card.subtitle!,
+ style: textTheme.bodyMuted,
+ ),
+ ),
+ const SizedBox(height: 20),
+ _MediaGrid(
+ media: card.media.take(6).toList(growable: false),
+ colorScheme: colorScheme,
+ ),
+ if (chips.isNotEmpty) ...[
+ const SizedBox(height: 18),
+ _DetailChips(
+ chips: chips,
+ colorScheme: colorScheme,
+ textTheme: textTheme,
+ ),
+ ],
+ const Spacer(),
+ ],
+ );
+ }
+}
+
+class _PaletteEntry {
+ _PaletteEntry({
+ required this.name,
+ required this.hex,
+ required this.count,
+ });
+
+ final String name;
+ final String hex;
+ final int count;
+
+ factory _PaletteEntry.fromJson(Map<String, Object?> json) {
+ return _PaletteEntry(
+ name: json["name"] as String? ?? "",
+ hex: json["hex"] as String? ?? "",
+ count: (json["count"] as num?)?.toInt() ?? 0,
+ );
+ }
+}
+
+List<_PaletteEntry> _paletteEntriesFromMeta(Map<String, Object?> meta) {
+ final List<dynamic> raw =
+ meta["palette"] as List<dynamic>? ?? const <dynamic>[];
+ return raw
+ .map(
+ (dynamic entry) =>
+ _PaletteEntry.fromJson((entry as Map).cast<String, Object?>()),
+ )
+ .where((_PaletteEntry entry) => entry.name.isNotEmpty)
+ .toList(growable: false);
+}
+
+class _PaletteSwatches extends StatelessWidget {
+ const _PaletteSwatches({
+ required this.entries,
+ required this.colorScheme,
+ required this.textTheme,
+ });
+
+ final List<_PaletteEntry> entries;
+ final EnteColorScheme colorScheme;
+ final EnteTextTheme textTheme;
+
+ @override
+ Widget build(BuildContext context) {
+ if (entries.isEmpty) {
+ return const SizedBox.shrink();
+ }
+ return Wrap(
+ spacing: 12,
+ runSpacing: 12,
+ children:
+ entries.map((entry) => _buildSwatch(entry)).toList(growable: false),
+ );
+ }
+
+ Widget _buildSwatch(_PaletteEntry entry) {
+ final Color resolved = _colorFromHex(entry.hex, colorScheme.primary500);
+ final Color swatchBackground = resolved.withValues(alpha: 0.16);
+ return Container(
+ padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
+ decoration: BoxDecoration(
+ color: swatchBackground,
+ borderRadius: BorderRadius.circular(16),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Container(
+ width: 18,
+ height: 18,
+ decoration: BoxDecoration(
+ color: resolved,
+ shape: BoxShape.circle,
+ ),
+ ),
+ const SizedBox(width: 10),
+ Text(
+ entry.name,
+ style: textTheme.smallMuted.copyWith(color: colorScheme.fillStrong),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+Color _colorFromHex(String hex, Color fallback) {
+ String sanitized = hex.trim();
+ if (sanitized.startsWith("#")) {
+ sanitized = sanitized.substring(1);
+ }
+ if (sanitized.length == 6) {
+ sanitized = "FF$sanitized";
+ }
+ final int? value = int.tryParse(sanitized, radix: 16);
+ if (value == null) {
+ return fallback;
+ }
+ return Color(value);
}