Skip to content

Instantly share code, notes, and snippets.

View risenW's full-sized avatar

Rising Odegua risenW

View GitHub Profile
console.log('Loading Model...')
home_ = process.cwd()
model_path = "file://"+ home_ + "/model/model.json"
console.log('Model Loaded Successfull')
console.log('Loading Model...')
model = await tf.loadLayersModel("file:///home/Projects/recommender-sys/recommender-books/model/model.json", false);
console.log('Model Loaded Successfull')
const functions = require('firebase-functions');
const express = require("express");
const bodyParser = require("body-parser");
const expressHbs = require("express-handlebars");
const books = require("./data/web_book_data.json")
const model = require("./model")
const app = express();
app.set("views", "./views");
app.set("view engine", "hbs");
b_id =list(ratings_df.book_id.unique())
b_id.remove(10000)
dict_map = {}
for i in b_id:
dict_map[i] = books_df_copy.iloc[i]['title']
out_v = open('vecs.tsv', 'w')
out_m = open('meta.tsv', 'w')
for i in b_id:
book = dict_map[i]
hist = model.fit([Xtrain.book_id, Xtrain.user_id], Xtrain.rating,
batch_size=64,
epochs=5,
verbose=1,
validation_data=([Xtest.book_id, Xtest.user_id], Xtest.rating))
#Book input network
input_books = tf.layers.Input(shape=[1])
embed_books = tf.layers.Embedding(nbook_id + 1,15)(input_books)
books_out = tf.layers.Flatten()(embed_books)
#user input network
input_users = tf.layers.Input(shape=[1])
embed_users = tf.layers.Embedding(nuser_id + 1,15)(input_users)
users_out = tf.layers.Flatten()(embed_users)
from sklearn.model_selection import train_test_split
Xtrain, Xtest = train_test_split(ratings_df, test_size=0.2, random_state=1)
print(f"Shape of train data: {Xtrain.shape}")
print(f"Shape of test data: {Xtest.shape}")
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
const tf = require('@tensorflow/tfjs-node')
const books = require("./data/web_book_data.json")
async function loadModel() {
console.log('Loading Model...')
model = await tf.loadLayersModel("file:///home/dsn/personal/Tfjs/TensorFlowjs_Projects/recommender-sys/recommender-books/model/model.json", false);
console.log('Model Loaded Successfull')
// model.summary()
app.get("/recommend", (req, res) => {
let userId = req.query.userId
if (Number(userId) > 53424 || Number(userId) < 0) {
res.send("User Id cannot be greater than 53,424 or less than 0!")
} else {
recs = model.recommend(userId)
.then((recs) => {
res.render("index", { recommendations: recs, forUser: true })
})
}