-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
119 lines (109 loc) · 2.83 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, {Component} from 'react';
import {StyleSheet, Text, View, Button, TextInput } from 'react-native';
import engine from 'spren-prediction-engine';
export default class sprenDemo extends Component {
state = {
nativeResult: "Model Not Loaded",
deviceId: "",
closeid: "",
ti: ""
}
init = async () => {
this.setState({ nativeResult: "loading..."})
try {
var response = await engine.init("your-api-key-here")
this.setState({ nativeResult: JSON.stringify(response)})
} catch(e) {
this.setState({ nativeResult: e})
}
}
evaluate = async () => {
this.setState({ deviceId: "loading..."})
try {
var response = await engine.evaluate(this.state.ti)
this.setState({ deviceId: JSON.stringify(response)})
} catch(e) {
this.setState({ deviceId: e})
}
}
close = async () => {
this.setState({ closeid: "loading..."})
try {
var response = await engine.close()
this.setState({ closeid: JSON.stringify(response)})
} catch(e) {
this.setState({ closeid: e})
}
}
text_input = (text) => {
this.setState({ ti: text })
}
render() {
return (
<View style={styles.container}>
<Text style={styles.instructions}>{this.state.nativeResult}</Text>
<Button
onPress={this.init}
title="init()"
color="#841584"
accessibilityLabel="Load Model Button"
/>
<TextInput style = {styles.input}
underlineColorAndroid = "transparent"
placeholder = "Enter text"
placeholderTextColor = "grey"
autoCapitalize = "none"
onChangeText = {this.text_input}
/>
<Text style={styles.instructions}>{this.state.deviceId}</Text>
<Button
onPress={this.evaluate}
title="evaluate()"
color="#841584"
accessibilityLabel="Test Model Button"
/>
<Text style={styles.instructions}>{this.state.closeid}</Text>
<Button
onPress={this.close}
title="close()"
color="#841584"
accessibilityLabel="Close Model Button"
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
marginBottom: 5,
},
welcome: {
fontSize: 20,
textAlign: 'center',
},
instructions: {
textAlign: 'center',
color: '#333333',
},
input: {
height: 40,
width:400,
borderColor: '#7a42f4',
borderWidth: 1,
color: 'black',
justifyContent: 'center',
alignItems: 'center',
margin: 15,
},
});