file('image'); $response = Http::attach( 'image', file_get_contents($image->getPathname()), $image->getClientOriginalName() )->post('http://127.0.0.1:5000/predict/hewan'); $data = json_decode($response->body(), true); $hasil = $data['prediction']; $confidence = $data['confidence']; $hewan = Hewan::where('name', $hasil)->first(); $url = url('images/foto/' . $hewan->foto); $hewan->foto = $url; $confiden = round($confidence * 100, 2) . '%'; $hewan->confidence = $confiden; // ambi nama dari tabel kategori, pluck id kategori $kategori = $hewan->kategori()->pluck('name')->first(); $hewan->kategori = $kategori; return response()->json([ 'status' => 'success', 'message' => 'Image successfully detected!', 'data' => $hewan, ]); } public function predictHewan2(Request $request) { $image = $request->file('image'); $response = Http::attach( 'image', file_get_contents($image->getPathname()), $image->getClientOriginalName() )->post('http://127.0.0.1:5000/predict/hewan'); $data = json_decode($response->body(), true); $hasil = $data['prediction']; $confidence = $data['confidence']; return response()->json([ 'status' => 'success', 'message' => 'Image successfully detected!', 'prediction' => $hasil, 'confidence' => $confidence, ]); } }