diff --git a/Frontend/src/pages/UserPanel/Ai.jsx b/Frontend/src/pages/UserPanel/Ai.jsx index 19c2ffd..db9f1d2 100644 --- a/Frontend/src/pages/UserPanel/Ai.jsx +++ b/Frontend/src/pages/UserPanel/Ai.jsx @@ -33,9 +33,9 @@ const Ai = () => { throw new Error("Prediction request failed"); } - const data = await response.json(); + const result = await response.json(); // Assuming the API returns a JSON object with an "output" field. - setPrediction(data.output || "No prediction returned"); + setPrediction(result.data || "No prediction returned"); } catch (err) { console.error("Error during prediction:", err); setError(err.message); diff --git a/models/server.js b/models/server.js index 7649954..c82087c 100644 --- a/models/server.js +++ b/models/server.js @@ -3,10 +3,19 @@ const express = require("express"); const { spawn } = require("child_process"); const path = require("path"); const upload = require("./Middleware/multer"); +const cors = require("cors"); const app = express(); const PORT = 3000; +const corsOptions = { + origin: "http://localhost:5173", + methods: "GET,HEAD,PUT,PATCH,POST,DELETE", + credentials: true, +}; + +app.use(cors(corsOptions)); + // Endpoint to run the Python script app.post("/predict", upload.single("image"), (req, res) => { console.log("File is uploaded successfully" + req.file?.path); @@ -22,7 +31,13 @@ app.post("/predict", upload.single("image"), (req, res) => { // Collect data from the script pythonProcess.stdout.on("data", (data) => { console.log(`Output: ${data}`); - res.send(data.toString()); // Send the output back to the client + + res.status(200).json({ + success: true, + message: "Image uploaded successfully", + data: data.toString(), + }); + //res.send(data.toString()); // Send the output back to the client }); // Handle errors