diff --git a/src/actions/index.js b/src/actions/index.js
index 7d62553..853d4b0 100644
--- a/src/actions/index.js
+++ b/src/actions/index.js
@@ -103,7 +103,7 @@ export const showNavigation = () => async (dispatch, getState) => {
});
}
-export const downloadModel = () => async (dispatch, getState) => {
+export const downloadModel = (modelUrl, modelType) => async (dispatch, getState) => {
let options = {
onProgress: (p)=>{
@@ -114,7 +114,15 @@ export const downloadModel = () => async (dispatch, getState) => {
}
}
- const model = await tf.loadLayersModel('/bai_model/model.json', options); // Load Model
+ let model;
+
+ if (modelType === "graph") {
+ model = await tf.loadGraphModel('run_tensorflowOutput_web_model/model.json');
+ } else if (modelType === "layers") {
+ model = await tf.loadLayersModel(modelUrl, options); // Load Model
+ } else {
+ model = null;
+ }
dispatch({
type: 'SET_MODEL',
@@ -130,7 +138,7 @@ export const loadingModel = () => async (dispatch, getState) => {
});
};
-export const predict = (image) => async (dispatch, getState) => {
+export const baiPredict = (image) => async (dispatch, getState) => {
let model = await getState().model.model;
let imdata = await tf.browser.fromPixels(image).resizeNearestNeighbor([550, 425]).toFloat().expandDims();
@@ -146,6 +154,19 @@ export const predict = (image) => async (dispatch, getState) => {
return prediction;
};
+export const dadJokesPredict = () => async (dispatch, getState) => {
+ let model = await getState().model.model;
+
+ let prediction = "";
+
+ dispatch({
+ type: 'SET_LAST_PRED',
+ payload: prediction
+ });
+
+ return prediction;
+};
+
export const error_msg = (message) => async (dispatch, getState) => {
console.log(message);
diff --git a/src/components/App.js b/src/components/App.js
index 1ae0300..88501c2 100644
--- a/src/components/App.js
+++ b/src/components/App.js
@@ -9,6 +9,7 @@ import ArticleEditor from './ArticleEditor';
import About from './About';
import Intro from './Intro';
import Bai from './Bai';
+import DadjokesAI from './DadjokesAI';
const App = (props) => {
return (
@@ -23,6 +24,7 @@ const App = (props) => {
} />
} />
} />
+ } />
} />
diff --git a/src/components/Bai.js b/src/components/Bai.js
index 5c473b6..f103110 100644
--- a/src/components/Bai.js
+++ b/src/components/Bai.js
@@ -1,9 +1,9 @@
import React from 'react';
import { connect } from 'react-redux';
-import {downloadModel, loadingModel, predict, error_msg} from '../actions'
+import {downloadModel, loadingModel, baiPredict, error_msg} from '../actions'
import ProgressBar from "./subcomponents/ProgressBar";
//import { Link } from 'react-router-dom';
-import './css/Bai.css';
+import './css/AIPages.css';
class Bai extends React.Component {
@@ -63,7 +63,7 @@ class Bai extends React.Component {
Would you like to download the model?
By clicking Accept below, you will download the model which may be between 100 mb in size to 1 gb.
-
{this.props.loadingModel();this.props.downloadModel()}}>Accept Download
+
{this.props.loadingModel();this.props.downloadModel('/bai_model/model.json', 'layers')}}>Accept Download
{this.props.loading}
{this.props.loading?this.props.downloadProgress+"%":""}
@@ -106,4 +106,4 @@ const mapStateToProps = (state) => {
return {model: state.model.model, loading: state.model.loading, last_prediction: state.model.last_prediction, downloadProgress: state.model.progress, error: state.model.error};
}
-export default connect(mapStateToProps, {downloadModel, loadingModel, predict, error_msg})(Bai);
+export default connect(mapStateToProps, {downloadModel, loadingModel, baiPredict, error_msg})(Bai);
diff --git a/src/components/DadjokesAI.js b/src/components/DadjokesAI.js
new file mode 100644
index 0000000..90e9886
--- /dev/null
+++ b/src/components/DadjokesAI.js
@@ -0,0 +1,113 @@
+import React from 'react';
+import { connect } from 'react-redux';
+import {downloadModel, loadingModel, dadJokesPredict, error_msg} from '../actions'
+import ProgressBar from "./subcomponents/ProgressBar";
+//import { Link } from 'react-router-dom';
+import './css/AIPages.css';
+
+
+class Bai extends React.Component {
+ /**
+ * Blank AI - Artificial Intelligence designed to distinguish photos of blank vs. non-blank paper scans
+ */
+
+
+ componentDidMount () {
+ document.title = "Dad Jokes AI";
+ }
+
+ extExtractor (filename) {
+ let name = filename.split('.');
+ let ext = name[name.length-1];
+ return ext
+ }
+
+ async fileUpload (target, predict) {
+
+ const [file] = target.files;
+
+ let image = document.getElementById("preview")
+
+ let image_ext = ['jpg', 'png'];
+
+ let file_ext = await this.extExtractor(file.name);
+
+ if (file && image_ext.includes(file_ext)) {
+
+ let imageBM = await createImageBitmap(file);
+
+ let prediction = await predict(imageBM);
+
+ console.log(this.declassify(prediction[0]));
+
+ image.src = await URL.createObjectURL(file);
+ image.classList.add('show');
+ } else {
+ this.props.error_msg('Please pass JPG or PNG file Only');
+ }
+ }
+
+ declassify(prediction) {
+ if (prediction > 0.5) {
+ return this.classes[1];
+ } else {
+ return this.classes[0];
+ }
+ }
+
+ render() {
+
+ let content = (this.props.model === null)?
+ (
+
+
Would you like to download the model?
+
By clicking Accept below, you will download the model which may be between 100 mb in size to 1 gb.
+
You also accept that the model is generated based off of unfiltered data which may have been trained with any words available to the human language.
+
{this.props.loadingModel();this.props.downloadModel('/dadjokes_model/model.json', 'graph')}}>Accept Download
+
{this.props.loading}
+
+ {this.props.loading?this.props.downloadProgress+"%":""}
+
+ )
+ :(
+
+
BAI Model Prediction
+
+
{this.props.last_prediction ? this.props.last_prediction[0]:"Waiting for Joke"}
+
+
+ {this.props.error}
+
+
+
{this.props.dadJokesPredict()}}>Generate New Dad Joke
+
+
+ );
+
+ return (
+
+ {content}
+
+
About
+
Note: This is a model with a small dataset, additional data is currently being collected, and will be used to retrain sometime soon. The current model will likely produce random babbling.
+
+ The model used in this page was based on the pretrained model GPT-2. You can find more information on openAI's site at https://openai.com/blog/tags/gpt-2/
+
+
+ The dataset that was used to retrain the model can be found at the following link
+ https://www.kaggle.com/datasets/camerinfigueroa/rdadjokes
+
+
+ The following Google Colab link will bring you to the notebook used to retrain GPT-2 with out dataset
+ Google Colab
+
+
+
+ );
+ }
+}
+const mapStateToProps = (state) => {
+ return {model: state.model.model, loading: state.model.loading, last_prediction: state.model.last_prediction, downloadProgress: state.model.progress, error: state.model.error};
+}
+
+export default connect(mapStateToProps, {downloadModel, loadingModel, dadJokesPredict, error_msg})(Bai);
diff --git a/src/components/css/Bai.css b/src/components/css/AIPages.css
similarity index 100%
rename from src/components/css/Bai.css
rename to src/components/css/AIPages.css