diff --git a/Frontend/src/pages/UserPanel/Ai.jsx b/Frontend/src/pages/UserPanel/Ai.jsx index f4ee2e4..19c2ffd 100644 --- a/Frontend/src/pages/UserPanel/Ai.jsx +++ b/Frontend/src/pages/UserPanel/Ai.jsx @@ -1,42 +1,43 @@ import React, { useState } from "react"; -import Loader from "../../components/Loader"; const Ai = () => { const [selectedFile, setSelectedFile] = useState(null); - const [result, setResult] = useState(""); + const [prediction, setPrediction] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const handleFileChange = (e) => { - setSelectedFile(e.target.files[0]); + if (e.target.files && e.target.files[0]) { + setSelectedFile(e.target.files[0]); + } }; const handleSubmit = async (e) => { e.preventDefault(); if (!selectedFile) return; + setLoading(true); - setResult(""); + setPrediction(""); setError(""); try { const formData = new FormData(); formData.append("image", selectedFile); - // Update the URL if needed. - const response = await fetch("http://localhost:8000/api/v1/vegetable", { + const response = await fetch("http://localhost:3000/predict", { method: "POST", body: formData, }); if (!response.ok) { - throw new Error("Failed to classify image"); + throw new Error("Prediction request failed"); } const data = await response.json(); - // Assume the API returns an object with an "output" field. - setResult(data.output || "No result provided"); + // Assuming the API returns a JSON object with an "output" field. + setPrediction(data.output || "No prediction returned"); } catch (err) { - console.error("Error:", err); + console.error("Error during prediction:", err); setError(err.message); } finally { setLoading(false); @@ -46,7 +47,7 @@ const Ai = () => { return (

- Vegetable Classifier + Plant disease prediction

{ disabled={loading || !selectedFile} className="w-full bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded focus:outline-none focus:ring-2 focus:ring-blue-500" > - {loading ? : "Upload and Classify"} + {loading ? "Predicting..." : "Predict"}
- {error &&

{error}

} - {result && ( + {error &&

{error}

} + {prediction && (
-

Result:

-

{result}

+

Prediction:

+

{prediction}

)}