diff --git a/containers/compose.yml b/containers/compose.yml
index b137a52..db21f05 100644
--- a/containers/compose.yml
+++ b/containers/compose.yml
@@ -37,6 +37,19 @@ services:
- 5672:5672
- 15672:15672
+
+ image-bucket:
+ container_name: image-bucket
+ image: minio/minio
+ ports:
+ - 9000:9000
+ - 9001:9001
+ environment:
+ MINIO_ACCESS_KEY: rares
+ MINIO_SECRET_KEY: rares2004
+ command: server /data --console-address ":9001"
+
+
# Nginx
core-services:
container_name: core-services
@@ -58,6 +71,3 @@ services:
- core-services
- event-service
-
-
-
diff --git a/containers/minio-data/.minio.sys/buckets/.bloomcycle.bin/xl.meta b/containers/minio-data/.minio.sys/buckets/.bloomcycle.bin/xl.meta
new file mode 100644
index 0000000..f60f6c4
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/.bloomcycle.bin/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/.usage-cache.bin.bkp/xl.meta b/containers/minio-data/.minio.sys/buckets/.usage-cache.bin.bkp/xl.meta
new file mode 100644
index 0000000..533489a
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/.usage-cache.bin.bkp/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/.usage-cache.bin/xl.meta b/containers/minio-data/.minio.sys/buckets/.usage-cache.bin/xl.meta
new file mode 100644
index 0000000..b023fd7
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/.usage-cache.bin/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/.usage.json/xl.meta b/containers/minio-data/.minio.sys/buckets/.usage.json/xl.meta
new file mode 100644
index 0000000..d52f082
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/.usage.json/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/others-reduced/.metadata.bin/xl.meta b/containers/minio-data/.minio.sys/buckets/others-reduced/.metadata.bin/xl.meta
new file mode 100644
index 0000000..bbd3030
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/others-reduced/.metadata.bin/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/others-reduced/.usage-cache.bin.bkp/xl.meta b/containers/minio-data/.minio.sys/buckets/others-reduced/.usage-cache.bin.bkp/xl.meta
new file mode 100644
index 0000000..9920e8b
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/others-reduced/.usage-cache.bin.bkp/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/others-reduced/.usage-cache.bin/xl.meta b/containers/minio-data/.minio.sys/buckets/others-reduced/.usage-cache.bin/xl.meta
new file mode 100644
index 0000000..eba02cf
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/others-reduced/.usage-cache.bin/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/others/.metadata.bin/xl.meta b/containers/minio-data/.minio.sys/buckets/others/.metadata.bin/xl.meta
new file mode 100644
index 0000000..3c60bec
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/others/.metadata.bin/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/others/.usage-cache.bin.bkp/xl.meta b/containers/minio-data/.minio.sys/buckets/others/.usage-cache.bin.bkp/xl.meta
new file mode 100644
index 0000000..6002fd9
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/others/.usage-cache.bin.bkp/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/others/.usage-cache.bin/xl.meta b/containers/minio-data/.minio.sys/buckets/others/.usage-cache.bin/xl.meta
new file mode 100644
index 0000000..2853bbb
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/others/.usage-cache.bin/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/profile-pictures-reduced/.metadata.bin/xl.meta b/containers/minio-data/.minio.sys/buckets/profile-pictures-reduced/.metadata.bin/xl.meta
new file mode 100644
index 0000000..ee122c1
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/profile-pictures-reduced/.metadata.bin/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/profile-pictures-reduced/.usage-cache.bin.bkp/xl.meta b/containers/minio-data/.minio.sys/buckets/profile-pictures-reduced/.usage-cache.bin.bkp/xl.meta
new file mode 100644
index 0000000..a26046a
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/profile-pictures-reduced/.usage-cache.bin.bkp/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/profile-pictures-reduced/.usage-cache.bin/xl.meta b/containers/minio-data/.minio.sys/buckets/profile-pictures-reduced/.usage-cache.bin/xl.meta
new file mode 100644
index 0000000..23635ec
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/profile-pictures-reduced/.usage-cache.bin/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/profile-pictures/.metadata.bin/xl.meta b/containers/minio-data/.minio.sys/buckets/profile-pictures/.metadata.bin/xl.meta
new file mode 100644
index 0000000..e3a64cf
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/profile-pictures/.metadata.bin/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/profile-pictures/.usage-cache.bin.bkp/xl.meta b/containers/minio-data/.minio.sys/buckets/profile-pictures/.usage-cache.bin.bkp/xl.meta
new file mode 100644
index 0000000..0ffe678
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/profile-pictures/.usage-cache.bin.bkp/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/buckets/profile-pictures/.usage-cache.bin/xl.meta b/containers/minio-data/.minio.sys/buckets/profile-pictures/.usage-cache.bin/xl.meta
new file mode 100644
index 0000000..44e857f
Binary files /dev/null and b/containers/minio-data/.minio.sys/buckets/profile-pictures/.usage-cache.bin/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/config/config.json/xl.meta b/containers/minio-data/.minio.sys/config/config.json/xl.meta
new file mode 100644
index 0000000..98362b2
Binary files /dev/null and b/containers/minio-data/.minio.sys/config/config.json/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/config/iam/format.json/xl.meta b/containers/minio-data/.minio.sys/config/iam/format.json/xl.meta
new file mode 100644
index 0000000..0ed3195
Binary files /dev/null and b/containers/minio-data/.minio.sys/config/iam/format.json/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/config/iam/sts/0C0LN72HPFBJ15CYMFGD/identity.json/xl.meta b/containers/minio-data/.minio.sys/config/iam/sts/0C0LN72HPFBJ15CYMFGD/identity.json/xl.meta
new file mode 100644
index 0000000..c6b091a
Binary files /dev/null and b/containers/minio-data/.minio.sys/config/iam/sts/0C0LN72HPFBJ15CYMFGD/identity.json/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/format.json b/containers/minio-data/.minio.sys/format.json
new file mode 100644
index 0000000..55d2c44
--- /dev/null
+++ b/containers/minio-data/.minio.sys/format.json
@@ -0,0 +1 @@
+{"version":"1","format":"xl-single","id":"2a2cd0d2-1eda-4f64-8c91-38d886f82fd0","xl":{"version":"3","this":"24c80554-3569-4f1f-a94d-f1e472d04a42","sets":[["24c80554-3569-4f1f-a94d-f1e472d04a42"]],"distributionAlgo":"SIPMOD+PARITY"}}
\ No newline at end of file
diff --git a/containers/minio-data/.minio.sys/pool.bin/xl.meta b/containers/minio-data/.minio.sys/pool.bin/xl.meta
new file mode 100644
index 0000000..a35457e
Binary files /dev/null and b/containers/minio-data/.minio.sys/pool.bin/xl.meta differ
diff --git a/containers/minio-data/.minio.sys/tmp/437225f4-5032-4810-855e-96d042e2a5fb b/containers/minio-data/.minio.sys/tmp/437225f4-5032-4810-855e-96d042e2a5fb
new file mode 100644
index 0000000..e36ee44
Binary files /dev/null and b/containers/minio-data/.minio.sys/tmp/437225f4-5032-4810-855e-96d042e2a5fb differ
diff --git a/containers/minio-data/others-reduced/67537c16ea37493fef90dfb3/xl.meta b/containers/minio-data/others-reduced/67537c16ea37493fef90dfb3/xl.meta
new file mode 100644
index 0000000..a3adbc4
Binary files /dev/null and b/containers/minio-data/others-reduced/67537c16ea37493fef90dfb3/xl.meta differ
diff --git a/containers/minio-data/others/675367184412ad238592685d/477592a0-8d66-46a2-9400-1b86c8c66772/part.1 b/containers/minio-data/others/675367184412ad238592685d/477592a0-8d66-46a2-9400-1b86c8c66772/part.1
new file mode 100644
index 0000000..d5b94ef
Binary files /dev/null and b/containers/minio-data/others/675367184412ad238592685d/477592a0-8d66-46a2-9400-1b86c8c66772/part.1 differ
diff --git a/containers/minio-data/others/675367184412ad238592685d/xl.meta b/containers/minio-data/others/675367184412ad238592685d/xl.meta
new file mode 100644
index 0000000..c853ae7
Binary files /dev/null and b/containers/minio-data/others/675367184412ad238592685d/xl.meta differ
diff --git a/containers/minio-data/profile-pictures/6753669c3cf40424744b5910/f28570bb-d52c-4b90-80b5-932edea09155/part.1 b/containers/minio-data/profile-pictures/6753669c3cf40424744b5910/f28570bb-d52c-4b90-80b5-932edea09155/part.1
new file mode 100644
index 0000000..d5b94ef
Binary files /dev/null and b/containers/minio-data/profile-pictures/6753669c3cf40424744b5910/f28570bb-d52c-4b90-80b5-932edea09155/part.1 differ
diff --git a/containers/minio-data/profile-pictures/6753669c3cf40424744b5910/xl.meta b/containers/minio-data/profile-pictures/6753669c3cf40424744b5910/xl.meta
new file mode 100644
index 0000000..e40942c
Binary files /dev/null and b/containers/minio-data/profile-pictures/6753669c3cf40424744b5910/xl.meta differ
diff --git a/image-service/pom.xml b/image-service/pom.xml
index 92d2153..be4f5fa 100644
--- a/image-service/pom.xml
+++ b/image-service/pom.xml
@@ -17,4 +17,42 @@
UTF-8
+
+
+ io.minio
+ minio
+ 8.5.2
+
+
+ io.springfox
+ springfox-swagger2
+ 3.0.0
+
+
+ io.springfox
+ springfox-boot-starter
+ 3.0.0
+
+
+ io.springfox
+ springfox-swagger-ui
+ 3.0.0
+
+
+ net.coobird
+ thumbnailator
+ 0.4.14
+
+
+ org.springframework
+ spring-test
+ 6.2.0
+ test
+
+
+ org.springframework
+ spring-test
+
+
+
\ No newline at end of file
diff --git a/image-service/src/main/java/com/stackbytes/Main.java b/image-service/src/main/java/com/stackbytes/Main.java
index ea7a7cc..050b4aa 100644
--- a/image-service/src/main/java/com/stackbytes/Main.java
+++ b/image-service/src/main/java/com/stackbytes/Main.java
@@ -1,7 +1,11 @@
package com.stackbytes;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
public class Main {
public static void main(String[] args) {
- System.out.println("Hello world!");
+ SpringApplication.run(Main.class, args);
}
}
\ No newline at end of file
diff --git a/image-service/src/main/java/com/stackbytes/configs/MinioConfig.java b/image-service/src/main/java/com/stackbytes/configs/MinioConfig.java
new file mode 100644
index 0000000..b41ebbe
--- /dev/null
+++ b/image-service/src/main/java/com/stackbytes/configs/MinioConfig.java
@@ -0,0 +1,24 @@
+package com.stackbytes.configs;
+
+import io.minio.MinioClient;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class MinioConfig {
+
+ @Value("${minio.username}")
+ private String username;
+
+ @Value("${minio.password}")
+ private String password;
+
+ @Bean
+ public MinioClient minioClient() {
+ return MinioClient.builder()
+ .endpoint("http://localhost:9000")
+ .credentials(username, password)
+ .build();
+ }
+}
diff --git a/image-service/src/main/java/com/stackbytes/controllers/ImageController.java b/image-service/src/main/java/com/stackbytes/controllers/ImageController.java
new file mode 100644
index 0000000..1e166ac
--- /dev/null
+++ b/image-service/src/main/java/com/stackbytes/controllers/ImageController.java
@@ -0,0 +1,45 @@
+package com.stackbytes.controllers;
+
+import com.stackbytes.models.dto.InsertImageResponseDto;
+import com.stackbytes.services.ImageService;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+@RestController
+public class ImageController {
+
+ private final ImageService imageService;
+
+ public ImageController(ImageService imageService) {
+ this.imageService = imageService;
+ }
+
+ @PostMapping("/insert")
+ public ResponseEntity insertImage(@RequestParam("file")MultipartFile file, @RequestParam("name") String name, @RequestParam("isProfilePicture") boolean isProfilePicture){
+ InsertImageResponseDto response = imageService.insertImage(file, name, isProfilePicture);
+ if(response.isSuccess()){
+ return ResponseEntity.ok(response);
+ }
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
+ }
+
+ @PostMapping("/insert-reduced")
+ public ResponseEntity insertReducedImage(@RequestParam("file")MultipartFile file, @RequestParam("name") String name, @RequestParam("isProfilePicture") boolean isProfilePicture) {
+ InsertImageResponseDto response = imageService.insertReducedImage(file, name, isProfilePicture);
+ if(response.isSuccess()){
+ return ResponseEntity.ok(response);
+ }
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
+ }
+
+ @PostMapping("/insert-avatar")
+ public ResponseEntity insertAvatarImage(@RequestParam("file")MultipartFile file, @RequestParam("name") String name, @RequestParam("reduced") boolean reduced) {
+ InsertImageResponseDto response = imageService.insertAvatarImage(file, name, reduced);
+ if(response.isSuccess()){
+ return ResponseEntity.ok(response);
+ }
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
+ }
+}
\ No newline at end of file
diff --git a/image-service/src/main/java/com/stackbytes/models/Image.java b/image-service/src/main/java/com/stackbytes/models/Image.java
new file mode 100644
index 0000000..a1cb7eb
--- /dev/null
+++ b/image-service/src/main/java/com/stackbytes/models/Image.java
@@ -0,0 +1,16 @@
+package com.stackbytes.models;
+
+import lombok.Builder;
+import lombok.Data;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document(collection = "images")
+@Data
+@Builder
+public class Image {
+ @Id
+ private String id;
+
+ private String name;
+}
diff --git a/image-service/src/main/java/com/stackbytes/models/dto/InsertImageResponseDto.java b/image-service/src/main/java/com/stackbytes/models/dto/InsertImageResponseDto.java
new file mode 100644
index 0000000..5214c7b
--- /dev/null
+++ b/image-service/src/main/java/com/stackbytes/models/dto/InsertImageResponseDto.java
@@ -0,0 +1,11 @@
+package com.stackbytes.models.dto;
+
+import lombok.Builder;
+import lombok.Data;
+
+@Data
+@Builder
+public class InsertImageResponseDto {
+ private boolean success;
+ private String message;
+}
diff --git a/image-service/src/main/java/com/stackbytes/services/ImageService.java b/image-service/src/main/java/com/stackbytes/services/ImageService.java
new file mode 100644
index 0000000..7b80c80
--- /dev/null
+++ b/image-service/src/main/java/com/stackbytes/services/ImageService.java
@@ -0,0 +1,169 @@
+package com.stackbytes.services;
+
+import com.stackbytes.models.Image;
+import com.stackbytes.models.dto.InsertImageResponseDto;
+import io.minio.MinioClient;
+import io.minio.PutObjectArgs;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+@Service
+public class ImageService {
+
+ private final MinioClient minioClient;
+
+ private final MongoTemplate mongoTemplate;
+
+ private final ReduceSizeService reduceSizeService;
+ public ImageService(MinioClient minioClient, MongoTemplate mongoTemplate, ReduceSizeService reduceSizeService) {
+ this.minioClient = minioClient;
+ this.mongoTemplate = mongoTemplate;
+ this.reduceSizeService = reduceSizeService;
+ }
+
+ public InsertImageResponseDto insertImage(MultipartFile multipartFile, String name, boolean isProfilePicture) {
+
+ if(multipartFile == null){
+ return InsertImageResponseDto.builder().success(false).message("Multipart file is null").build();
+ }
+
+ String contentType = multipartFile.getContentType();
+
+ if(contentType == null || !contentType.startsWith("image")){
+ return InsertImageResponseDto.builder().success(false).message("Invalid content type").build();
+ }
+
+ if(isProfilePicture) {
+ Image image = Image.builder().name(name).build();
+ Image insertedImage = mongoTemplate.insert(image);
+ try {
+ minioClient.putObject(
+ PutObjectArgs.builder()
+ .bucket("profile-pictures")
+ .stream(multipartFile.getInputStream(), multipartFile.getSize(), -1)
+ .contentType(contentType)
+ .object(insertedImage.getId())
+ .build()
+ );
+ } catch (Exception e) {
+ return InsertImageResponseDto.builder().success(false).message("Error : " + e.getMessage()).build();
+ }
+ return InsertImageResponseDto.builder().success(true).message(insertedImage.getId()).build();
+ } else {
+ Image image = Image.builder().name(name).build();
+ Image insertedImage = mongoTemplate.insert(image);
+ try {
+ minioClient.putObject(
+ PutObjectArgs.builder()
+ .bucket("others")
+ .stream(multipartFile.getInputStream(), multipartFile.getSize(), -1)
+ .contentType(contentType)
+ .object(insertedImage.getId())
+ .build()
+ );
+ } catch (Exception e) {
+ return InsertImageResponseDto.builder().success(false).message("Error : " + e.getMessage()).build();
+ }
+ return InsertImageResponseDto.builder().success(true).message(insertedImage.getId()).build();
+ }
+ }
+
+ public InsertImageResponseDto insertReducedImage(MultipartFile multipartFile, String name, boolean isProfilePicture) {
+ if(multipartFile == null){
+ return InsertImageResponseDto.builder().success(false).message("Multipart file is null").build();
+ }
+
+ String contentType = multipartFile.getContentType();
+
+ if(contentType == null || !contentType.startsWith("image")){
+ return InsertImageResponseDto.builder().success(false).message("Invalid content type").build();
+ }
+
+ if(isProfilePicture) {
+ Image image = Image.builder().name(name).build();
+ Image insertedImage = mongoTemplate.insert(image);
+
+ try {
+ MultipartFile reducedImage = reduceSizeService.reduceSize(multipartFile);
+ minioClient.putObject(
+ PutObjectArgs.builder()
+ .bucket("profile-pictures-reduced")
+ .stream(reducedImage.getInputStream(), reducedImage.getSize(), -1)
+ .contentType(contentType)
+ .object(insertedImage.getId())
+ .build()
+ );
+ } catch (Exception e) {
+ return InsertImageResponseDto.builder().success(false).message("Error : " + e.getMessage()).build();
+ }
+ return InsertImageResponseDto.builder().success(true).message(insertedImage.getId()).build();
+ } else {
+ Image image = Image.builder().name(name).build();
+ Image insertedImage = mongoTemplate.insert(image);
+
+ try {
+ MultipartFile reducedImage = reduceSizeService.reduceSize(multipartFile);
+
+ minioClient.putObject(
+ PutObjectArgs.builder()
+ .bucket("others-reduced")
+ .stream(reducedImage.getInputStream(), reducedImage.getSize(), -1) // Pass the size explicitly
+ .contentType(reducedImage.getContentType())
+ .object(insertedImage.getId())
+ .build()
+ );
+ } catch (Exception e) {
+ return InsertImageResponseDto.builder().success(false).message("Error : " + e.getMessage()).build();
+ }
+ return InsertImageResponseDto.builder().success(true).message(insertedImage.getId()).build();
+ }
+ }
+
+ public InsertImageResponseDto insertAvatarImage(MultipartFile multipartFile, String name, boolean reduced) {
+
+ if(multipartFile == null){
+ return InsertImageResponseDto.builder().success(false).message("Multipart file is null").build();
+ }
+
+ String contentType = multipartFile.getContentType();
+
+ if(contentType == null || !contentType.startsWith("image")){
+ return InsertImageResponseDto.builder().success(false).message("Invalid content type").build();
+ }
+
+ Image image = Image.builder().name(name).build();
+ Image insertedImage = mongoTemplate.insert(image);
+
+ if(reduced) {
+ try {
+ MultipartFile reducedImage = reduceSizeService.reduceSize(multipartFile);
+ minioClient.putObject(
+ PutObjectArgs.builder()
+ .bucket("avatars-reduced")
+ .stream(reducedImage.getInputStream(), reducedImage.getSize(), -1)
+ .contentType(contentType)
+ .object(insertedImage.getId())
+ .build()
+ );
+ return InsertImageResponseDto.builder().success(true).message(insertedImage.getId()).build();
+ } catch (Exception e) {
+ return InsertImageResponseDto.builder().success(false).message("Error : " + e.getMessage()).build();
+ }
+ } else {
+ try {
+ minioClient.putObject(
+ PutObjectArgs.builder()
+ .bucket("avatars")
+ .stream(multipartFile.getInputStream(), multipartFile.getSize(), -1)
+ .contentType(contentType)
+ .object(insertedImage.getId())
+ .build()
+ );
+ return InsertImageResponseDto.builder().success(true).message(insertedImage.getId()).build();
+ } catch (Exception e) {
+ return InsertImageResponseDto.builder().success(false).message("Error : " + e.getMessage()).build();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/image-service/src/main/java/com/stackbytes/services/ReduceSizeService.java b/image-service/src/main/java/com/stackbytes/services/ReduceSizeService.java
new file mode 100644
index 0000000..1b5ed6b
--- /dev/null
+++ b/image-service/src/main/java/com/stackbytes/services/ReduceSizeService.java
@@ -0,0 +1,48 @@
+package com.stackbytes.services;
+
+import net.coobird.thumbnailator.Thumbnails;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.mock.web.MockMultipartFile;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+@Service
+public class ReduceSizeService {
+
+ public MultipartFile reduceSize(MultipartFile multipartFile) throws IOException {
+ BufferedImage originalImage = Thumbnails.of(multipartFile.getInputStream()).scale(1.0).asBufferedImage();
+
+ // Calculate the target width and height (reduce by 5x)
+ int width = originalImage.getWidth() / 5;
+ int height = originalImage.getHeight() / 5;
+
+ // Resize the image using Thumbnails
+ BufferedImage resizedImage = Thumbnails.of(originalImage)
+ .size(width, height)
+ .asBufferedImage();
+
+ String fileName = multipartFile.getOriginalFilename();
+ String fileType = fileName.substring(fileName.lastIndexOf('.') + 1);
+
+ System.out.println(fileType);
+
+ if(!fileType.equals("png") && !fileType.equals("jpg") && !fileType.equals("jpeg")) {
+ throw new IOException("Invalid file type");
+ }
+ // Convert the resized image to byte array
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ ImageIO.write(resizedImage, fileType, outputStream);
+ byte[] resizedBytes = outputStream.toByteArray();
+
+ return new MockMultipartFile(
+ "file",
+ multipartFile.getOriginalFilename(),
+ multipartFile.getContentType(),
+ resizedBytes
+ );
+ }
+}
diff --git a/machine-learning-service/Dataset-Mental-Disorders.csv b/machine-learning-service/Dataset-Mental-Disorders.csv
new file mode 100644
index 0000000..8c2ba90
--- /dev/null
+++ b/machine-learning-service/Dataset-Mental-Disorders.csv
@@ -0,0 +1,121 @@
+Patient Number,Sadness,Euphoric,Exhausted,Sleep dissorder,Mood Swing,Suicidal thoughts,Anorxia,Authority Respect,Try-Explanation,Aggressive Response,Ignore & Move-On,Nervous Break-down,Admit Mistakes,Overthinking,Sexual Activity,Concentration,Optimisim,Expert Diagnose
+Patiant-01,Usually,Seldom,Sometimes,Sometimes,YES,YES ,NO,NO,YES,NO,NO,YES,YES,YES,3 From 10,3 From 10,4 From 10,Bipolar Type-2
+Patiant-02,Usually,Seldom,Usually,Sometimes,NO,YES,NO,NO,NO,NO,NO,NO,NO,NO,4 From 10,2 From 10,5 From 10,Depression
+Patiant-03,Sometimes,Most-Often,Sometimes,Sometimes,YES,NO,NO,NO,YES,YES,NO,YES,YES,NO,6 From 10,5 From 10,7 From 10,Bipolar Type-1
+Patiant-04,Usually,Seldom,Usually,Most-Often,YES,YES,YES,NO,YES,NO,NO,NO,NO,NO,3 From 10,2 From 10,2 From 10,Bipolar Type-2
+Patiant-05,Usually,Usually,Sometimes,Sometimes,NO,NO,NO,NO,NO,NO,NO,YES,YES,YES,5 From 10,5 From 10,6 From 10,Normal
+Patiant-06,Usually,Sometimes,Sometimes,Most-Often,NO,YES,YES,YES,NO,NO,NO,NO,YES,NO,3 From 10,5 From 10,5 From 10,Depression
+Patiant-07,Seldom,Usually,Seldom,Sometimes,YES,YES,YES,NO,YES,YES,NO,YES,YES,YES,7 From 10,2 From 10,9 From 10,Bipolar Type-1
+Patiant-08,Usually,Sometimes,Sometimes,Sometimes,NO,NO,NO,NO,YES,NO,NO,NO,NO,YES,5 From 10,5 From 10,5 From 10,Normal
+Patiant-09,Most-Often,Seldom,Most-Often,Usually,YES,YES,YES,NO,YES,YES,NO,YES,NO,NO,8 From 10,2 From 10,3 From 10,Bipolar Type-2
+Patiant-10,Usually,Seldom,Most-Often,Sometimes,NO,NO,NO,NO,YES,NO,NO,YES,YES,YES,3 From 10,4 From 10,2 From 10,Depression
+Patiant-11,Seldom,Sometimes,Seldom,Seldom,NO,NO,NO,YES,NO,NO,NO,NO,YES,NO,5 From 10,7 From 10,8 From 10,Normal
+Patiant-12,Seldom,Sometimes,Sometimes,Usually,YES,YES,YES,NO,YES,YES,NO,YES,NO,YES,8 From 10,4 From 10,9 From 10,Bipolar Type-1
+Patiant-13,Most-Often,Sometimes,Most-Often,Usually,YES,YES,YES,NO,YES,YES,NO,YES,NO,YES,9 From 10,2 From 10,4 From 10,Bipolar Type-2
+Patiant-14,Usually,Usually,Sometimes,Sometimes,NO,NO,NO,YES,NO,NO,NO,NO,NO,NO,5 From 10,7 From 10,5 From 10,Normal
+Patiant-15,Usually,Seldom,Most-Often,Usually,NO,YES,NO,NO,YES,NO,YES,YES,YES,YES,5 From 10,4 From 10,2 From 10,Depression
+Patiant-16,Sometimes,Sometimes,Sometimes,Sometimes,YES,NO,YES,NO,YES,YES,NO,NO,NO,YES,6 From 10,4 From 10,6 From 10,Bipolar Type-1
+Patiant-17,Sometimes,Usually,Sometimes,Sometimes,NO,NO,NO,NO,YES,NO,NO,NO,YES,NO,5 From 10,4 From 10,6 From 10,Normal
+Patiant-18,Usually,Sometimes,Most-Often,Sometimes,YES,NO,NO,NO,YES,YES,NO,YES,NO,YES,6 From 10,2 From 10,3 From 10,Bipolar Type-1
+Patiant-19,Most-Often,Seldom,Most-Often,Most-Often,NO,NO,NO,NO,YES,NO,YES,YES,YES,YES,3 From 10,4 From 10,1 From 10,Depression
+Patiant-20,Sometimes,Usually,Usually,Sometimes,NO,NO,NO,YES,YES,YES,NO,NO,YES,YES,4 From 10,4 From 10,6 From 10,Normal
+Patiant-21,Sometimes,Sometimes,Sometimes,Usually,YES,NO,NO,YES,YES,YES,NO,YES,YES,YES,6 From 10,2 From 10,3 From 10,Bipolar Type-2
+Patiant-22,Usually,Sometimes,Sometimes,Sometimes,YES,YES,YES,NO,YES,YES,NO,NO,NO,YES,6 From 10,4 From 10,6 From 10,Bipolar Type-1
+Patiant-23,Sometimes,Sometimes,Sometimes,Usually,NO,NO,YES,YES,YES,NO,NO,NO,NO,YES,3 From 10,7 From 10,6 From 10,Normal
+Patiant-24,Usually,Sometimes,Usually,Sometimes,NO,NO,NO,NO,NO,YES,NO,NO,NO,NO,4 From 10,4 From 10,2 From 10,Depression
+Patiant-25,Usually,Sometimes,Sometimes,Usually,YES,NO,NO,NO,NO,NO,NO,YES,YES,YES,4 From 10,4 From 10,3 From 10,Bipolar Type-2
+Patiant-26,Sometimes,Sometimes,Sometimes,Seldom,NO,NO,NO,YES,NO,NO,YES,NO,YES,NO,6 From 10,6 From 10,5 From 10,Normal
+Patiant-27,Sometimes,Sometimes,Usually,Sometimes,NO,NO,NO,NO,YES,YES,NO,NO,NO,NO,3 From 10,4 From 10,2 From 10,Normal
+Patiant-28,Usually,Seldom,Usually,Usually,NO,NO,NO,NO,YES,NO,YES,YES,NO,YES,5 From 10,2 From 10,4 From 10,Depression
+Patiant-29,Usually,Seldom,Usually,Usually,YES,YES,YES,YES,YES,NO,YES,YES,NO,YES,2 From 10,2 From 10,3 From 10,Bipolar Type-2
+Patiant-30,Sometimes,Sometimes,Sometimes,Seldom,NO,YES,NO,YES,NO,NO,YES,NO,YES,NO,5 From 10,5 From 10,5 From 10,Normal
+Patiant-31,Sometimes,Most-Often,Sometimes,Sometimes,YES,YES,NO,YES,YES,YES,NO,YES,NO,NO,3 From 10,2 From 10,6 From 10,Bipolar Type-1
+Patiant-32,Most-Often,Sometimes,Most-Often,Sometimes,NO,YES,NO,YES,NO,NO,YES,NO,YES,YES,4 From 10,4 From 10,3 From 10,Depression
+Patiant-33,Sometimes,Seldom,Most-Often,Seldom,YES,YES,NO,YES,NO,NO,YES,YES,NO,YES,5 From 10,5 From 10,4 From 10,Bipolar Type-2
+Patiant-34,Sometimes,Usually,Sometimes,Most-Often,YES,YES,YES,NO,YES,YES,NO,NO,NO,NO,6 From 10,5 From 10,4 From 10,Bipolar Type-1
+Patiant-35,Sometimes,Seldom,Sometimes,Seldom,NO,NO,NO,YES,YES,NO,YES,NO,YES,NO,5 From 10,5 From 10,6 From 10,Normal
+Patiant-36,Most-Often,Seldom,Usually,Sometimes,NO,NO,NO,NO,NO,NO,YES,YES,YES,YES,2 From 10,4 From 10,4 From 10,Depression
+Patiant-37,Sometimes,Seldom,Usually,Seldom,YES,YES,YES,NO,YES,NO,NO,YES,NO,NO,8 From 10,5 From 10,5 From 10,Bipolar Type-1
+Patiant-38,Usually,Seldom,Most-Often,Sometimes,YES,YES,NO,YES,YES,NO,NO,YES,NO,NO,4 From 10,3 From 10,4 From 10,Bipolar Type-2
+Patiant-39,Sometimes,Seldom,Usually,Sometimes,NO,NO,NO,YES,NO,NO,YES,NO,YES,NO,5 From 10,5 From 10,3 From 10,Normal
+Patiant-40,Sometimes,Sometimes,Sometimes,Sometimes,YES,YES,NO,YES,YES,YES,NO,NO,YES,NO,3 From 10,3 From 10,2 From 10,Bipolar Type-2
+Patiant-41,Usually,Sometimes,Usually,Sometimes,NO,YES,NO,NO,YES,NO,NO,NO,NO,YES,8 From 10,2 From 10,2 From 10,Depression
+Patiant-42,Most-Often,Seldom,Most-Often,Most-Often,YES,YES,YES,NO,YES,NO,YES,YES,NO,YES,2 From 10,2 From 10,2 From 10,Bipolar Type-2
+Patiant-43,Seldom,Sometimes,Sometimes,Seldom,YES,NO,NO,YES,NO,NO,YES,NO,YES,YES,4 From 10,4 From 10,6 From 10,Normal
+Patiant-44,Sometimes,Most-Often,Seldom,Usually,YES,YES,YES,NO,NO,YES,NO,YES,NO,NO,8 From 10,2 From 10,8 From 10,Bipolar Type-1
+Patiant-45,Most-Often,Seldom,Most-Often,Most-Often,NO,YES,YES,NO,NO,NO,YES,YES,NO,YES,4 From 10,3 From 10,3 From 10,Depression
+Patiant-46,Most-Often,Sometimes,Usually,Sometimes,YES,NO,NO,YES,NO,NO,YES,YES,YES,NO,4 From 10,4 From 10,4 From 10,Bipolar Type-2
+Patiant-47,Sometimes,Seldom,Usually,Seldom,NO,NO,NO,YES,NO,NO,YES,NO,YES,NO,4 From 10,5 From 10,5 From 10,Normal
+Patiant-48,Most-Often,Seldom,Usually,Most-Often,YES,YES,NO,NO,YES,NO,YES,NO,YES,NO,4 From 10,3 From 10,6 From 10,Bipolar Type-2
+Patiant-49,Seldom,Usually,Usually,Usually,YES,YES,NO,NO,NO,NO,NO,YES,NO,NO,5 From 10,4 From 10,6 From 10,Bipolar Type-1
+Patiant-50,Usually,Seldom,Most-Often,Usually,NO,NO,NO,NO,NO,YES,NO,NO,NO,NO,4 From 10,4 From 10,3 From 10,Depression
+Patiant-51,Sometimes,Sometimes,Sometimes,Seldom,NO,NO,NO,YES,NO,YES,YES,NO,YES,NO,4 From 10,4 From 10,6 From 10,Normal
+Patiant-52,Usually,Seldom,Sometimes,Sometimes,YES,NO,NO,NO,YES,YES,NO,NO,NO,NO,3 From 10,3 From 10,3 From 10,Bipolar Type-2
+Patiant-53,Most-Often,Seldom,Most-Often,Most-Often,NO,YES,NO,NO,NO,NO,YES,YES,NO,YES,2 From 10,2 From 10,2 From 10,Depression
+Patiant-54,Seldom,Usually,Seldom,Most-Often,YES,NO,YES,YES,NO,YES,YES,YES,NO,NO,5 From 10,1 From 10,4 From 10,Bipolar Type-1
+Patiant-55,Most-Often,Seldom,Most-Often,Most-Often,YES,YES,YES,NO,NO,YES,NO,YES,YES,YES,2 From 10,2 From 10,1 From 10,Bipolar Type-2
+Patiant-56,Sometimes,Seldom,Usually,Usually,NO,NO,YES,NO,NO,YES,YES,YES,NO,NO,3 From 10,4 From 10,3 From 10,Normal
+Patiant-57,Seldom,Most-Often,Most-Often,Most-Often,YES,NO,NO,YES,YES,NO,YES,NO,NO,YES,5 From 10,4 From 10,6 From 10,Bipolar Type-1
+Patiant-58,Seldom,Usually,Most-Often,Most-Often,YES,NO,YES,NO,YES,NO,NO,NO,NO,YES,7 From 10,2 From 10,2 From 10,Bipolar Type-1
+Patiant-59,Sometimes,Sometimes,Most-Often,Usually,NO,NO,YES,YES,NO,NO,NO,YES,YES,YES,3 From 10,7 From 10,4 From 10,Depression
+Patiant-60,Seldom,Most-Often,Seldom,Seldom,NO,NO,YES,NO,YES,NO,YES,NO,YES,NO,5 From 10,4 From 10,4 From 10,Normal
+Patiant-61,Usually,Sometimes,Usually,Usually,YES,YES,NO,NO,NO,YES,YES,NO,YES,YES,4 From 10,4 From 10,3 From 10,Bipolar Type-2
+Patiant-62,Usually,Sometimes,Usually,Most-Often,NO,YES,NO,NO,YES,NO,NO,YES,YES,YES,4 From 10,5 From 10,2 From 10,Depression
+Patiant-63,Usually,Seldom,Sometimes,Usually,YES,NO,YES,NO,NO,YES,NO,NO,NO,NO,7 From 10,4 From 10,6 From 10,Bipolar Type-1
+Patiant-64,Most-Often,Seldom,Sometimes,Usually,YES,YES,YES,YES,NO,YES,NO,YES,NO,NO,4 From 10,4 From 10,4 From 10,Bipolar Type-2
+Patiant-65,Sometimes,Sometimes,Sometimes,Usually,NO,YES,YES,NO,YES,YES,NO,NO,NO,NO,5 From 10,6 From 10,5 From 10,Normal
+Patiant-66,Usually,Seldom,Most-Often,Sometimes,NO,YES,NO,NO,NO,NO,NO,NO,YES,YES,3 From 10,5 From 10,2 From 10,Depression
+Patiant-67,Sometimes,Usually,Usually,Usually,NO,NO,YES,YES,YES,NO,YES,NO,NO,NO,7 From 10,6 From 10,6 From 10,Normal
+Patiant-68,Sometimes,Seldom,Most-Often,Most-Often,YES,NO,YES,NO,YES,YES,NO,YES,YES,NO,8 From 10,4 From 10,5 From 10,Bipolar Type-1
+Patiant-69,Usually,Seldom,Most-Often,Usually,YES,YES,NO,NO,YES,NO,NO,YES,YES,NO,7 From 10,5 From 10,4 From 10,Bipolar Type-2
+Patiant-70,Sometimes,Usually,Sometimes,Usually,NO,YES,NO,NO,NO,YES,NO,NO,YES,YES,5 From 10,4 From 10,6 From 10,Bipolar Type-1
+Patiant-71,Sometimes,Seldom,Usually,Sometimes,NO,YES,NO,NO,NO,YES,YES,YES,YES,YES,2 From 10,6 From 10,2 From 10,Depression
+Patiant-72,Seldom,Seldom,Sometimes,Sometimes,YES,YES,NO,YES,YES,YES,YES,YES,YES,YES,5 From 10,3 From 10,5 From 10,Bipolar Type-2
+Patiant-73,Sometimes,Seldom,Most-Often,Sometimes,YES,NO,NO,NO,NO,YES,NO,YES,NO,NO,7 From 10,5 From 10,7 From 10,Bipolar Type-1
+Patiant-74,Sometimes,Usually,Sometimes,Seldom,NO,NO,NO,YES,NO,NO,NO,YES,NO,YES,6 From 10,4 From 10,5 From 10,Normal
+Patiant-75,Usually,Sometimes,Seldom,Seldom,YES,NO,YES,NO,NO,YES,NO,YES,YES,YES,3 From 10,7 From 10,4 From 10,Bipolar Type-2
+Patiant-76,Usually,Sometimes,Usually,Seldom,NO,YES,YES,NO,YES,NO,YES,YES,NO,NO,7 From 10,3 From 10,2 From 10,Depression
+Patiant-77,Usually,Sometimes,Seldom,Seldom,NO,NO,YES,NO,NO,YES,NO,NO,NO,YES,8 From 10,2 From 10,8 From 10,Depression
+Patiant-78,Usually,Seldom,Seldom,Seldom,YES,NO,NO,NO,NO,YES,YES,NO,NO,NO,2 From 10,2 From 10,4 From 10,Bipolar Type-2
+Patiant-79,Usually,Sometimes,Sometimes,Seldom,NO,NO,NO,NO,YES,YES,YES,NO,NO,NO,6 From 10,6 From 10,6 From 10,Normal
+Patiant-80,Most-Often,Seldom,Most-Often,Sometimes,NO,YES,YES,YES,NO,YES,YES,YES,YES,YES,6 From 10,3 From 10,3 From 10,Depression
+Patiant-81,Sometimes,Sometimes,Usually,Most-Often,YES,YES,NO,NO,NO,YES,NO,NO,YES,YES,8 From 10,2 From 10,6 From 10,Bipolar Type-1
+Patiant-82,Most-Often,Sometimes,Sometimes,Usually,YES,NO,NO,NO,NO,NO,NO,YES,NO,NO,2 From 10,4 From 10,5 From 10,Bipolar Type-2
+Patiant-83,Usually,Seldom,Most-Often,Sometimes,NO,NO,NO,NO,NO,YES,NO,YES,YES,YES,5 From 10,7 From 10,4 From 10,Depression
+Patiant-84,Seldom,Usually,Most-Often,Most-Often,NO,NO,YES,YES,YES,YES,YES,NO,YES,YES,7 From 10,8 From 10,6 From 10,Normal
+Patiant-85,Usually,Seldom,Seldom,Sometimes,YES,NO,NO,NO,NO,YES,YES,YES,NO,NO,7 From 10,6 From 10,7 From 10,Bipolar Type-1
+Patiant-86,Sometimes,Sometimes,Most-Often,Usually,YES,YES,YES,YES,NO,YES,YES,YES,YES,YES,2 From 10,4 From 10,1 From 10,Bipolar Type-2
+Patiant-87,Usually,Sometimes,Usually,Most-Often,NO,YES,NO,NO,YES,NO,NO,YES,NO,YES,4 From 10,7 From 10,2 From 10,Depression
+Patiant-88,Usually,Seldom,Sometimes,Sometimes,YES,NO,YES,NO,NO,YES,NO,YES,YES,YES,9 From 10,2 From 10,8 From 10,Bipolar Type-1
+Patiant-89,Seldom,Most-Often,Sometimes,Usually,NO,NO,YES,YES,NO,YES,NO,YES,NO,YES,6 From 10,6 From 10,7 From 10,Bipolar Type-1
+Patiant-90,Sometimes,Usually,Seldom,Sometimes,NO,NO,NO,YES,YES,YES,YES,YES,YES,NO,7 From 10,3 From 10,5 From 10,Normal
+Patiant-91,Most-Often,Seldom,Usually,Usually,NO,YES,NO,YES,NO,YES,YES,YES,NO,YES,4 From 10,4 From 10,3 From 10,Depression
+Patiant-92,Usually,Sometimes,Most-Often,Sometimes,YES,YES,NO,YES,NO,YES,NO,NO,YES,YES,2 From 10,6 From 10,4 From 10,Bipolar Type-2
+Patiant-93,Sometimes,Usually,Most-Often,Usually,NO,NO,NO,YES,NO,NO,NO,NO,YES,YES,5 From 10,7 From 10,6 From 10,Normal
+Patiant-94,Usually,Seldom,Usually,Usually,YES,NO,YES,NO,YES,YES,NO,NO,YES,NO,7 From 10,1 From 10,7 From 10,Bipolar Type-1
+Patiant-95,Most-Often,Seldom,Most-Often,Sometimes,NO,YES,NO,NO,NO,NO,NO,NO,NO,YES,2 From 10,8 From 10,4 From 10,Depression
+Patiant-96,Usually,Sometimes,Seldom,Sometimes,YES,YES,NO,YES,YES,NO,YES,YES,NO,YES,1 From 10,4 From 10,5 From 10,Bipolar Type-2
+Patiant-97,Sometimes,Usually,Seldom,Sometimes,YES,NO,NO,YES,NO,YES,NO,NO,YES,YES,5 From 10,5 From 10,8 From 10,Bipolar Type-1
+Patiant-98,Sometimes,Most-Often,Sometimes,Seldom,NO,NO,NO,YES,NO,NO,NO,NO,YES,YES,6 From 10,2 From 10,6 From 10,Normal
+Patiant-99,Most-Often,Sometimes,Usually,Usually,NO,YES,NO,NO,YES,NO,NO,YES,NO,NO,3 From 10,7 From 10,2 From 10,Depression
+Patiant-100,Usually,Seldom,Usually,Sometimes,YES,YES,YES,YES,YES,NO,NO,NO,YES,NO,2 From 10,5 From 10,2 From 10,Bipolar Type-2
+Patiant-101,Usually,Sometimes,Seldom,Usually,YES,NO,NO,NO,NO,YES,YES,NO,NO,YES,8 From 10,1 From 10,8 From 10,Bipolar Type-1
+Patiant-102,Sometimes,Seldom,Most-Often,Most-Often,NO,YES,NO,NO,NO,NO,YES,NO,YES,NO,1 From 10,6 From 10,3 From 10,Depression
+Patiant-103,Seldom,Usually,Seldom,Sometimes,NO,YES,NO,NO,YES,YES,NO,YES,YES,NO,6 From 10,6 From 10,5 From 10,Bipolar Type-1
+Patiant-104,Sometimes,Most-Often,Sometimes,Seldom,NO,NO,YES,YES,NO,YES,YES,YES,YES,NO,7 From 10,4 From 10,5 From 10,Normal
+Patiant-105,Usually,Sometimes,Most-Often,Usually,YES,YES,YES,NO,NO,NO,YES,YES,NO,NO,2 From 10,4 From 10,4 From 10,Bipolar Type-2
+Patiant-106,Most-Often,Seldom,Usually,Most-Often,NO,YES,YES,YES,NO,NO,YES,NO,YES,YES,3 From 10,7 From 10,1 From 10,Depression
+Patiant-107,Seldom,Usually,Sometimes,Seldom,NO,NO,NO,NO,YES,YES,YES,NO,YES,YES,6 From 10,5 From 10,7 From 10,Normal
+Patiant-108,Sometimes,Sometimes,Usually,Usually,NO,YES,YES,NO,YES,YES,NO,YES,YES,NO,8 From 10,7 From 10,5 From 10,Depression
+Patiant-109,Usually,Sometimes,Sometimes,Sometimes,YES,YES,YES,YES,NO,YES,YES,YES,NO,YES,2 From 10,1 From 10,1 From 10,Bipolar Type-2
+Patiant-110,Most-Often,Seldom,Seldom,Sometimes,NO,NO,YES,NO,YES,NO,NO,YES,NO,YES,3 From 10,3 From 10,3 From 10,Depression
+Patiant-111,Sometimes,Most-Often,Usually,Usually,NO,NO,NO,YES,NO,NO,NO,NO,YES,NO,4 From 10,7 From 10,5 From 10,Normal
+Patiant-112,Sometimes,Sometimes,Usually,Most-Often,YES,YES,NO,YES,NO,NO,YES,YES,NO,NO,4 From 10,1 From 10,2 From 10,Bipolar Type-2
+Patiant-113,Seldom,Usually,Usually,Sometimes,YES,NO,YES,YES,YES,YES,YES,YES,NO,YES,8 From 10,8 From 10,5 From 10,Bipolar Type-1
+Patiant-114,Sometimes,Seldom,Sometimes,Most-Often,YES,YES,YES,NO,NO,NO,YES,NO,YES,YES,1 From 10,5 From 10,1 From 10,Bipolar Type-2
+Patiant-115,Seldom,Sometimes,Seldom,Usually,NO,NO,NO,NO,NO,YES,NO,NO,NO,NO,5 From 10,8 From 10,7 From 10,Normal
+Patiant-116,Most-Often,Seldom,Usually,Sometimes,NO,YES,NO,NO,YES,NO,YES,NO,NO,YES,2 From 10,5 From 10,3 From 10,Depression
+Patiant-117,Sometimes,Sometimes,Sometimes,Seldom,YES,NO,NO,NO,NO,YES,NO,NO,NO,YES,6 From 10,7 From 10,8 From 10,Bipolar Type-1
+Patiant-118,Usually,Sometimes,Usually,Sometimes,YES,NO,YES,YES,NO,NO,NO,YES,NO,YES,1 From 10,5 From 10,3 From 10,Bipolar Type-2
+Patiant-119,Usually,Sometimes,Seldom,Seldom,NO,YES,YES,NO,YES,YES,YES,NO,YES,YES,7 From 10,7 From 10,7 From 10,Depression
+Patiant-120,Sometimes,Usually,Seldom,Usually,NO,NO,NO,YES,YES,NO,YES,YES,NO,NO,7 From 10,3 From 10,8 From 10,Normal
diff --git a/machine-learning-service/__pycache__/modelService.cpython-312.pyc b/machine-learning-service/__pycache__/modelService.cpython-312.pyc
new file mode 100644
index 0000000..c63aa1b
Binary files /dev/null and b/machine-learning-service/__pycache__/modelService.cpython-312.pyc differ
diff --git a/machine-learning-service/api.py b/machine-learning-service/api.py
new file mode 100644
index 0000000..69125e4
--- /dev/null
+++ b/machine-learning-service/api.py
@@ -0,0 +1,15 @@
+from flask import Flask, request,jsonify, make_response
+import modelService
+
+app = Flask(__name__)
+
+@app.route("/predict" , methods=["POST"])
+def predict():
+ if(request.is_json):
+ data = request.get_json()
+ result = modelService.modelService(data)
+ return make_response(jsonify(result), 200)
+ return make_response(jsonify({"message": "Request body must be JSON"}), 400)
+
+if __name__ == "__main__":
+ app.run(debug=True)
\ No newline at end of file
diff --git a/machine-learning-service/model.joblib b/machine-learning-service/model.joblib
new file mode 100644
index 0000000..d6fc123
Binary files /dev/null and b/machine-learning-service/model.joblib differ
diff --git a/machine-learning-service/model.py b/machine-learning-service/model.py
new file mode 100644
index 0000000..92dfa08
--- /dev/null
+++ b/machine-learning-service/model.py
@@ -0,0 +1,49 @@
+import pandas as pd
+import joblib
+from sklearn.ensemble import RandomForestClassifier
+from sklearn.preprocessing import OneHotEncoder
+from sklearn.model_selection import train_test_split, cross_val_score
+from sklearn.metrics import accuracy_score
+from sklearn.compose import ColumnTransformer
+
+dataset = pd.read_csv('Dataset-Mental-Disorders.csv')
+
+dataset.columns = dataset.columns.str.replace(" ", "_")
+
+# Options for the complete display of the dataset
+pd.set_option('display.max_columns', None)
+pd.set_option('display.max_colwidth', None)
+pd.set_option('display.expand_frame_repr', False)
+
+dataset = dataset.drop('Patient_Number', axis=1)
+
+dataset['Suicidal_thoughts'] = dataset['Suicidal_thoughts'].replace('YES ', 'YES')
+
+yes_no_cols = ['Mood_Swing', 'Suicidal_thoughts', 'Anorxia', 'Authority_Respect', 'Try-Explanation', 'Aggressive_Response', 'Ignore_&_Move-On', 'Nervous_Break-down', 'Admit_Mistakes', 'Overthinking']
+
+for col in yes_no_cols:
+ dataset[col] = dataset[col].map({'YES': 1, 'NO': 0}).astype(int)
+
+X = dataset.drop(columns=['Expert_Diagnose'],axis=1)
+y = dataset['Expert_Diagnose']
+
+X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
+
+encoder = OneHotEncoder(handle_unknown='ignore')
+X_train_encoded = encoder.fit_transform(X_train)
+X_test_encoded = encoder.transform(X_test)
+
+rf = RandomForestClassifier()
+rf.fit(X_train_encoded, y_train)
+
+y_pred = rf.predict(X_test_encoded)
+
+accuracy = accuracy_score(y_test, y_pred)
+
+print(f"Accuracy: {accuracy:.2f}")
+
+print(f"Cross Validation Score: {cross_val_score(rf, X_train_encoded, y_train, cv=5).mean():.2f}")
+
+# joblib.dump(rf, 'model.joblib')
+
+# joblib.dump(encoder, 'preprocessor.joblib')
\ No newline at end of file
diff --git a/machine-learning-service/modelService.py b/machine-learning-service/modelService.py
new file mode 100644
index 0000000..c05f427
--- /dev/null
+++ b/machine-learning-service/modelService.py
@@ -0,0 +1,35 @@
+import pandas as pd
+import joblib
+
+# Options for the complete display of the dataset
+pd.set_option('display.max_columns', None)
+pd.set_option('display.max_colwidth', None)
+pd.set_option('display.expand_frame_repr', False)
+
+columns = [
+ "Sadness", "Euphoric", "Exhausted", "Sleep_dissorder", "Mood_Swing",
+ "Suicidal_thoughts", "Anorxia", "Authority_Respect", "Try-Explanation",
+ "Aggressive_Response", "Ignore_&_Move-On", "Nervous_Break-down",
+ "Admit_Mistakes", "Overthinking", "Sexual_Activity", "Concentration",
+ "Optimisim"
+]
+
+model = joblib.load('model.joblib')
+
+preprocessor = joblib.load('preprocessor.joblib')
+
+def modelService(data) :
+ row = [data[column] for column in columns]
+ dataset = pd.DataFrame([row], columns=columns)
+ dataset['Suicidal_thoughts'] = dataset['Suicidal_thoughts'].replace('YES ', 'YES')
+
+ yes_no_cols = ['Mood_Swing', 'Suicidal_thoughts', 'Anorxia', 'Authority_Respect', 'Try-Explanation', 'Aggressive_Response', 'Ignore_&_Move-On', 'Nervous_Break-down', 'Admit_Mistakes', 'Overthinking']
+
+ for col in yes_no_cols:
+ dataset[col] = dataset[col].apply(lambda x: x if x in ['YES', 'NO'] else 'NO')
+
+ for col in yes_no_cols:
+ dataset[col] = dataset[col].map({'YES': 1, 'NO': 0}).astype(int)
+ dataset = preprocessor.transform(dataset)
+ prediction = model.predict(dataset)
+ return prediction[0]
\ No newline at end of file
diff --git a/machine-learning-service/preprocessor.joblib b/machine-learning-service/preprocessor.joblib
new file mode 100644
index 0000000..2af4c41
Binary files /dev/null and b/machine-learning-service/preprocessor.joblib differ