Skip to content

Commit 2204e1f

Browse files
authored
feat: Image embeddings (#397)
## Description Introducing image embeddings feature. TODO: benchmarks Everything else is good to review. ### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update (improves or adds clarity to existing documentation) ### Tested on - [x] iOS - [x] Android ### Related issues #353 ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have updated the documentation accordingly - [ ] My changes generate no new warnings ### Additional notes <!-- Include any additional information, assumptions, or context that reviewers might need to understand this PR. -->
1 parent 0787eca commit 2204e1f

38 files changed

Lines changed: 1631 additions & 141 deletions

File tree

apps/text-embeddings/android/app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
<action android:name="android.intent.action.MAIN"/>
2121
<category android:name="android.intent.category.LAUNCHER"/>
2222
</intent-filter>
23+
<intent-filter>
24+
<action android:name="android.intent.action.VIEW"/>
25+
<category android:name="android.intent.category.DEFAULT"/>
26+
<category android:name="android.intent.category.BROWSABLE"/>
27+
<data android:scheme="rne-embeddings"/>
28+
</intent-filter>
2329
</activity>
2430
</application>
2531
</manifest>

apps/text-embeddings/android/app/src/main/java/com/anonymous/textembeddings/MainActivity.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class MainActivity : ReactActivity() {
2727
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
2828
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
2929
*/
30-
override fun createReactActivityDelegate(): ReactActivityDelegate =
31-
ReactActivityDelegateWrapper(
30+
override fun createReactActivityDelegate(): ReactActivityDelegate {
31+
return ReactActivityDelegateWrapper(
3232
this,
3333
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED,
3434
object : DefaultReactActivityDelegate(
@@ -37,6 +37,7 @@ class MainActivity : ReactActivity() {
3737
fabricEnabled,
3838
) {},
3939
)
40+
}
4041

4142
/**
4243
* Align the back button behavior with Android S

apps/text-embeddings/android/app/src/main/java/com/anonymous/textembeddings/MainApplication.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ import com.facebook.soloader.SoLoader
1414
import expo.modules.ApplicationLifecycleDispatcher
1515
import expo.modules.ReactNativeHostWrapper
1616

17-
class MainApplication :
18-
Application(),
19-
ReactApplication {
17+
class MainApplication : Application(), ReactApplication {
2018
override val reactNativeHost: ReactNativeHost =
2119
ReactNativeHostWrapper(
2220
this,
2321
object : DefaultReactNativeHost(this) {
2422
override fun getPackages(): List<ReactPackage> {
2523
val packages = PackageList(this).packages
2624
// Packages that cannot be autolinked yet can be added manually here, for example:
27-
// packages.add(new MyReactNativePackage());
25+
// packages.add(MyReactNativePackage())
2826
return packages
2927
}
3028

apps/text-embeddings/app.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"icon": "./assets/icon.png",
88
"userInterfaceStyle": "light",
99
"newArchEnabled": true,
10+
"scheme": "rne-embeddings",
1011
"splash": {
1112
"image": "./assets/splash-icon.png",
1213
"resizeMode": "contain",
@@ -25,6 +26,7 @@
2526
},
2627
"web": {
2728
"favicon": "./assets/favicon.png"
28-
}
29+
},
30+
"plugins": ["expo-router"]
2931
}
3032
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { Drawer } from 'expo-router/drawer';
2+
import ColorPalette from '../colors';
3+
import React, { useState } from 'react';
4+
import { Text, StyleSheet, View } from 'react-native';
5+
6+
import {
7+
DrawerContentComponentProps,
8+
DrawerContentScrollView,
9+
DrawerItemList,
10+
} from '@react-navigation/drawer';
11+
import { GeneratingContext } from '../context';
12+
13+
interface CustomDrawerProps extends DrawerContentComponentProps {
14+
isGenerating: boolean;
15+
}
16+
17+
function CustomDrawerContent(props: CustomDrawerProps) {
18+
const { isGenerating, ...otherProps } = props;
19+
return (
20+
<DrawerContentScrollView {...otherProps}>
21+
{!isGenerating ? (
22+
<DrawerItemList {...otherProps} />
23+
) : (
24+
<View style={styles.centerContent}>
25+
<Text style={styles.mainText}>Model is generating...</Text>
26+
<Text style={styles.subText}>Interrupt before switching model</Text>
27+
</View>
28+
)}
29+
</DrawerContentScrollView>
30+
);
31+
}
32+
33+
export default function _layout() {
34+
const [isGenerating, setIsGenerating] = useState(false);
35+
36+
return (
37+
<GeneratingContext
38+
value={{
39+
setGlobalGenerating: (newState: boolean) => {
40+
setIsGenerating(newState);
41+
},
42+
}}
43+
>
44+
<Drawer
45+
drawerContent={(props) => (
46+
<CustomDrawerContent {...props} isGenerating={isGenerating} />
47+
)}
48+
screenOptions={{
49+
drawerActiveTintColor: ColorPalette.primary,
50+
drawerInactiveTintColor: '#888',
51+
headerTintColor: ColorPalette.primary,
52+
headerTitleStyle: { color: ColorPalette.primary },
53+
}}
54+
>
55+
<Drawer.Screen
56+
name="text-embeddings/index"
57+
options={{
58+
drawerLabel: 'Text embeddings',
59+
title: 'Text embeddings',
60+
headerTitleStyle: { color: ColorPalette.primary },
61+
}}
62+
/>
63+
<Drawer.Screen
64+
name="clip-embeddings/index"
65+
options={{
66+
drawerLabel: 'CLIP embeddings',
67+
title: 'CLIP embeddings',
68+
headerTitleStyle: { color: ColorPalette.primary },
69+
}}
70+
/>
71+
<Drawer.Screen
72+
name="index"
73+
options={{
74+
drawerLabel: () => null,
75+
title: 'Main Menu',
76+
drawerItemStyle: { display: 'none' },
77+
}}
78+
/>
79+
</Drawer>
80+
</GeneratingContext>
81+
);
82+
}
83+
84+
const styles = StyleSheet.create({
85+
centerContent: {
86+
flex: 1,
87+
justifyContent: 'center',
88+
alignItems: 'center',
89+
padding: 20,
90+
},
91+
mainText: {
92+
fontSize: 18,
93+
fontWeight: 'bold',
94+
marginBottom: 10,
95+
color: ColorPalette.primary,
96+
},
97+
subText: {
98+
fontSize: 14,
99+
color: ColorPalette.strongPrimary,
100+
},
101+
});

0 commit comments

Comments
 (0)