Skip to content

Commit

Permalink
Final commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sonuku092 committed Mar 15, 2024
1 parent b9bd62e commit c36495d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions backend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AppService } from './app.service';
import { ChatsModule } from '../chats/chats.module';
import { ChatsController } from 'src/chats/chats.controller';
import { UsersModule } from 'src/users/users.module';
import { HeartDiseaseModule } from 'src/models/heart-disease/heart-disease.module';

@Module({
imports: [ChatsModule, UsersModule],
Expand Down
12 changes: 7 additions & 5 deletions backend/src/models/heart-disease/heart-disease-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,30 @@ export class HeartDiseaseModel {
private loadHeartDiseaseDataset() {
try {
// Load the CSV data
const csvData = fs.readFileSync('./data/heart.csv', 'utf8');

const csvData = fs.readFileSync('./heart.csv', 'utf8');
// Parse the CSV data
const rows = csvData.split('\n').map(row => row.split(','));

// Extract features and labels
const x = rows.map(row => row.slice(0, -1).map(parseFloat));
const y = rows.map(row => parseFloat(row[row.length - 1]));

// Convert data to tensors
const xs = tf.tensor2d(x);
const ys = tf.tensor2d(y, [y.length, 1]);

return { xs, ys };
} catch (error) {
console.error('Error loading heart disease dataset:', error);
return null;
}
}


private async trainHeartDiseaseModel() {
const { xs, ys } = this.loadHeartDiseaseDataset();

if (xs && ys) {
const model = tf.sequential();
model.add(tf.layers.dense({ units: 10, inputShape: [xs.shape[1]], activation: 'relu' }));
Expand Down
4 changes: 2 additions & 2 deletions backend/src/models/heart-disease/heart-disease.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import { Controller, Post, Body } from '@nestjs/common';
import { HeartDiseaseService } from './heart-disease.service';

@Controller('heart-disease')
@Controller('heart')
export class HeartDiseaseController {
constructor(private readonly heartDiseaseService: HeartDiseaseService) {}

@Post('predict')
@Post()
async predictHeartDisease(@Body() data: number[]): Promise<number[]> {
return this.heartDiseaseService.predictHeartDisease(data);
}
Expand Down
9 changes: 9 additions & 0 deletions backend/src/models/heart-disease/heart-disease.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { HeartDiseaseController } from './heart-disease.controller';
import { HeartDiseaseService } from './heart-disease.service';

@Module({
controllers: [HeartDiseaseController],
providers: [HeartDiseaseService],
})
export class HeartDiseaseModule {}
2 changes: 1 addition & 1 deletion frontend/src/components/Login/Login.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Login.js
import React, { useEffect, useState } from 'react';
import styles from './Login.module.css';
import InputControl from '../InputControl/InputControl';
import InputControl from '../assets/InputControl/InputControl';
import { Link, useNavigate } from 'react-router-dom';
import { signInWithEmailAndPassword } from 'firebase/auth';
import { auth } from '../../firebase';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Profile/Profile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import styles from './Profile.module.css'
import OutputControl from '../InputControl/OutputControl'
import OutputControl from '../assets/InputControl/OutputControl'
import { Firestore } from 'firebase/firestore'
import { db } from '../../firebase'

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Signup/Signup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Signup.js
import React, { useEffect, useState } from 'react';
import styles from './Signup.module.css';
import InputControl from '../InputControl/InputControl';
import InputControl from '../assets/InputControl/InputControl';
import { Link, useNavigate } from 'react-router-dom';
import { createUserWithEmailAndPassword, updateProfile } from 'firebase/auth';
import { auth, db } from '../../firebase'; // Import collection and db
Expand Down

0 comments on commit c36495d

Please sign in to comment.