Skip to content

Commit 9f729ff

Browse files
committed
Added the feature to chat with image
1 parent a01d8f7 commit 9f729ff

File tree

12 files changed

+536
-30
lines changed

12 files changed

+536
-30
lines changed

AiApi.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,26 @@ async function GetGeminiProResponse(historyData, message) {
5151
return response.text().length>0 ? response.text(): "Hmm.. I didn't get that.";
5252
}
5353

54-
export {GetGeminiProResponse}
54+
async function GetImageResponse(image,message) {
55+
function fileToGenerativePart(img, mimeType) {
56+
return {
57+
inlineData: {
58+
data: img,
59+
mimeType
60+
},
61+
};
62+
}
63+
64+
const model = genAI.getGenerativeModel({ model: "gemini-pro-vision" });
65+
66+
const prompt = message;
67+
68+
const imageParts = image.map((img) => fileToGenerativePart(img.base64, img.type));
69+
70+
const result = await model.generateContent([prompt, ...imageParts]);
71+
const response = await result.response;
72+
return response.text().length>0 ? response.text(): "Hmm.. I didn't get that.";
73+
74+
}
75+
76+
export {GetGeminiProResponse, GetImageResponse}

App.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {OnboardingScreen} from './Screens/OnboardingScreen';
1111
import {Initial} from './Screens/Initial';
1212
import {EsseyPage} from './Screens/EsseyPage';
1313
import {PlagiarismPage} from './Screens/Plagiarism';
14+
import Features from "./Screens/Features";
15+
import ImageChat from "./Screens/ImageChat";
1416

1517
function App(): JSX.Element {
1618
const Stack = createNativeStackNavigator();
@@ -47,6 +49,20 @@ function App(): JSX.Element {
4749
headerShown: false,
4850
}}
4951
/>
52+
<Stack.Screen
53+
name={'ImageChat'}
54+
component={ImageChat}
55+
options={{
56+
headerShown: false,
57+
}}
58+
/>
59+
<Stack.Screen
60+
name={'FeaturesPage'}
61+
component={Features}
62+
options={{
63+
headerShown: false,
64+
}}
65+
/>
5066
<Stack.Screen
5167
name={'MailPage'}
5268
component={MailPage}

Assets/Image.png

27.2 KB
Loading

Components/Global/TopHeader.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {Dimensions, Text, TouchableOpacity, View} from 'react-native';
44
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome';
55
import {faArrowLeft} from '@fortawesome/free-solid-svg-icons';
66

7-
export const TopHeader = ({navigation, text}) => {
7+
export const TopHeader = ({navigation, text, righticon}) => {
88
const width = Dimensions.get('window').width;
99
return (
1010
<View
@@ -34,7 +34,10 @@ export const TopHeader = ({navigation, text}) => {
3434
}}>
3535
{text}
3636
</Text>
37-
<View></View>
37+
{righticon && righticon}
38+
{!righticon && <View style={{
39+
width:width * 0.07,
40+
}}/>}
3841
</View>
3942
);
4043
};

Components/ImageView/ImageView.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {Button, Image, Modal, Text} from "react-native";
2+
import Dialog from "react-native-dialog";
3+
import {memo} from "react";
4+
5+
function ImageView({visible, setvisible,image}) {
6+
return <Dialog.Container contentStyle={{
7+
backgroundColor:'#1e1b38',
8+
}} onBackdropPress={()=>{
9+
setvisible(false)
10+
}} visible={visible} style={{
11+
backgroundColor:'#1e1b38',
12+
padding:0,
13+
margin:0
14+
}}>
15+
{image.length !== 0 && <Image source={{
16+
uri:image[0]?.uri??''
17+
}} style={{
18+
height:300,
19+
width:300,
20+
}}/>}
21+
{image.length === 0 && <Text style={{
22+
color:'white',
23+
textAlign:'center',
24+
paddingBottom:10
25+
}}>No image selected</Text>}
26+
<Button title={'Close'} onPress={()=>{setvisible(false)}}/>
27+
</Dialog.Container>
28+
}
29+
export default memo(ImageView)

Screens/ChatPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const ChatPage = ({navigation,route}) => {
2626
const [VoiceRecording,setVoiceRecording] = useState(false);
2727
const [value,setvalue] = useState('');
2828
const [chat,setchat] = useState([]);
29-
async function OnPressSend(val) {
29+
async function OnPressSend(val,images) {
3030
const historyData = [...chat]
3131
setchat((history)=>[...history,
3232
{role:'user',

Screens/Features.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import {Dimensions, ScrollView, Text, View} from "react-native";
2+
import React from "react";
3+
import {EachCard} from "./HomePage";
4+
5+
const windowWidth = Dimensions.get('window').width;
6+
const windowHeight = Dimensions.get('window').height;
7+
export default function Features({navigation}) {
8+
return <ScrollView
9+
showsHorizontalScrollIndicator={false}
10+
showsVerticalScrollIndicator={false}
11+
style={{
12+
height: windowHeight,
13+
backgroundColor: '#1e1b38',
14+
paddingHorizontal: windowWidth * 0.045,
15+
paddingTop: 10,
16+
}}
17+
contentContainerStyle={{
18+
paddingBottom: 100,
19+
}}>
20+
<Text
21+
style={{
22+
color: 'white',
23+
fontSize: windowWidth * 0.07,
24+
fontWeight: 'bold',
25+
alignSelf: 'flex-start',
26+
marginTop: 10,
27+
marginBottom:10
28+
}}>
29+
All Features
30+
</Text>
31+
<View
32+
style={{
33+
flexDirection: 'row',
34+
gap: 20,
35+
}}>
36+
<EachCard
37+
delay={0}
38+
title={'MAIL'}
39+
discreption={'Generate professional mail in one tap.'}
40+
image={require('../Assets/mail.png')}
41+
color={'rgba(33, 64, 133, 0.30)'}
42+
navigation={navigation}
43+
route={'MailPage'}
44+
/>
45+
<EachCard
46+
delay={150}
47+
title={'CODE'}
48+
discreption={'Generate error free code in one tap.'}
49+
image={require('../Assets/webpage.png')}
50+
color={'rgba(146, 97, 32, 0.25)'}
51+
navigation={navigation}
52+
route={'CodePage'}
53+
/>
54+
</View>
55+
<View
56+
style={{
57+
flexDirection: 'row',
58+
gap: 20,
59+
marginTop: 20,
60+
}}>
61+
<EachCard
62+
delay={250}
63+
title={'Image'}
64+
discreption={'Chat with image in one tap.'}
65+
image={require('../Assets/Image.png')}
66+
color={'rgba(48,136,99,0.18)'}
67+
navigation={navigation}
68+
route={'ImageChat'}
69+
/>
70+
<EachCard
71+
delay={350}
72+
title={'PLAGIARISM'}
73+
discreption={'Remove plagiarism in one tap.'}
74+
image={require('../Assets/ai.png')}
75+
color={'#2c2250'}
76+
route={'PlagiarismPage'}
77+
navigation={navigation}
78+
/>
79+
</View>
80+
<View
81+
style={{
82+
flexDirection: 'row',
83+
gap: 20,
84+
marginTop: 20,
85+
}}>
86+
<EachCard
87+
delay={450}
88+
title={'ESSAY'}
89+
discreption={'Generate essay on any topic in one tap.'}
90+
image={require('../Assets/Essey.png')}
91+
color={'rgba(136, 48, 48, 0.18)'}
92+
navigation={navigation}
93+
route={'EsseyPage'}
94+
/>
95+
<View style={{
96+
flex: 1,
97+
borderRadius: 10,
98+
alignContent: 'center',
99+
justifyContent: 'center',
100+
alignItems: 'center',
101+
paddingBottom: 20,
102+
}}>
103+
</View>
104+
</View>
105+
</ScrollView>
106+
}

0 commit comments

Comments
 (0)