diff --git a/backend/src/app/app.module.ts b/backend/src/app/app.module.ts index 01dc342d..2cf939ec 100644 --- a/backend/src/app/app.module.ts +++ b/backend/src/app/app.module.ts @@ -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], diff --git a/backend/src/models/heart-disease/heart-disease-model.ts b/backend/src/models/heart-disease/heart-disease-model.ts index ef930120..fa5bd26e 100644 --- a/backend/src/models/heart-disease/heart-disease-model.ts +++ b/backend/src/models/heart-disease/heart-disease-model.ts @@ -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' })); diff --git a/backend/src/models/heart-disease/heart-disease.controller.ts b/backend/src/models/heart-disease/heart-disease.controller.ts index 30fe2368..cd7bba28 100644 --- a/backend/src/models/heart-disease/heart-disease.controller.ts +++ b/backend/src/models/heart-disease/heart-disease.controller.ts @@ -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 { return this.heartDiseaseService.predictHeartDisease(data); } diff --git a/backend/src/models/heart-disease/heart-disease.module.ts b/backend/src/models/heart-disease/heart-disease.module.ts new file mode 100644 index 00000000..29f969cf --- /dev/null +++ b/backend/src/models/heart-disease/heart-disease.module.ts @@ -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 {} \ No newline at end of file diff --git a/frontend/src/components/Login/Login.js b/frontend/src/components/Login/Login.js index 1995fc98..0f50675b 100644 --- a/frontend/src/components/Login/Login.js +++ b/frontend/src/components/Login/Login.js @@ -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'; diff --git a/frontend/src/components/Profile/Profile.js b/frontend/src/components/Profile/Profile.js index 999beffb..d9372216 100644 --- a/frontend/src/components/Profile/Profile.js +++ b/frontend/src/components/Profile/Profile.js @@ -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' diff --git a/frontend/src/components/Signup/Signup.js b/frontend/src/components/Signup/Signup.js index 80f836cc..55dfaf9d 100644 --- a/frontend/src/components/Signup/Signup.js +++ b/frontend/src/components/Signup/Signup.js @@ -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