35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
// use App\Models\Classification; // -> Dihapus karena tidak butuh simpan riwayat lagi
|
|
use App\Models\Image;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class ClassificationController extends Controller
|
|
{
|
|
public function classify($image_id)
|
|
{
|
|
// 1. Ambil gambar yang baru saja diupload
|
|
$image = Image::findOrFail($image_id);
|
|
|
|
// 2. Path gambar di storage
|
|
$path = storage_path('app/public/' . $image->image_path);
|
|
|
|
// 3. Kirim gambar ke API Python
|
|
$response = Http::attach(
|
|
'image',
|
|
file_get_contents($path),
|
|
basename($path)
|
|
)->post('http://127.0.0.1:5000/predict');
|
|
|
|
$result = $response->json();
|
|
|
|
// KODE SIMPAN KE DATABASE (Classification::create) SUDAH DIHAPUS DI SINI
|
|
|
|
// 4. Langsung kembalikan hasil ke halaman view (blade)
|
|
// Gunakan ->with('result', $result) agar datanya bisa ditampilkan di frontend
|
|
return redirect()->back()->with('success', 'Klasifikasi berhasil')->with('result', $result);
|
|
}
|
|
} |