173 lines
5.3 KiB
PHP
173 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Data;
|
|
use App\Models\Hewan;
|
|
use App\Models\Kategori;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Intervention\Image\Facades\Image;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
return view('landing.pages.index');
|
|
}
|
|
|
|
public function mediaHewan()
|
|
{
|
|
$kategori = Kategori::with('hewan')->get();
|
|
return view('landing.pages.media.hewan', [
|
|
'kategori' => $kategori
|
|
]);
|
|
}
|
|
|
|
public function getHewan($id)
|
|
{
|
|
$hewan = Hewan::where('kategori_id', $id)->get();
|
|
foreach ($hewan as $item) {
|
|
$item->foto = url('images/foto/' . $item->foto);
|
|
}
|
|
return response()->json($hewan);
|
|
}
|
|
|
|
public function mediaBuah()
|
|
{
|
|
return view('landing.pages.media.buah');
|
|
}
|
|
|
|
public function mediaAngka()
|
|
{
|
|
return view('landing.pages.media.angka');
|
|
}
|
|
|
|
public function mediaHuruf()
|
|
{
|
|
return view('landing.pages.media.huruf');
|
|
}
|
|
|
|
public function predictHewan(Request $request)
|
|
{
|
|
$request->validate([
|
|
'image' => 'required|image|mimes:jpeg,png,jpg|max:20000',
|
|
], [
|
|
'image.required' => 'Image is required!',
|
|
'image.image' => 'File must be an image!',
|
|
'image.mimes' => 'File must be jpeg, png, atau jpg!',
|
|
'image.max' => 'File size must be less than 20MB!',
|
|
]);
|
|
|
|
$image = $request->file('image');
|
|
$image_name = time() . '.' . $image->extension();
|
|
$image_path = public_path('images/hewan/') . $image_name;
|
|
$image->move(public_path('images/hewan/'), $image_name);
|
|
|
|
$response = Http::attach(
|
|
'image',
|
|
file_get_contents($image_path),
|
|
$image_name
|
|
)->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();
|
|
|
|
|
|
return response()->json(['hasil' => $hasil, 'gambar' => $image_name, 'hewan' => $hewan, 'confidence' => $confidence]);
|
|
}
|
|
|
|
public function predictBuah(Request $request)
|
|
{
|
|
$request->validate([
|
|
'image' => 'required|image|mimes:jpeg,png,jpg|max:20000',
|
|
], [
|
|
'image.required' => 'Image is required!',
|
|
'image.image' => 'File must be an image!',
|
|
'image.mimes' => 'File must be jpeg, png, atau jpg!',
|
|
'image.max' => 'File size must be less than 20MB!',
|
|
]);
|
|
|
|
$image = $request->file('image');
|
|
$image_name = time() . '.' . $image->extension();
|
|
$image_path = public_path('images/buah/') . $image_name;
|
|
$image->move(public_path('images/buah/'), $image_name);
|
|
|
|
$response = Http::attach(
|
|
'image',
|
|
file_get_contents($image_path),
|
|
$image_name
|
|
)->post('http://127.0.0.1:5000/predict/buah');
|
|
|
|
$data = json_decode($response->body(), true);
|
|
$hasil = $data['prediction'];
|
|
|
|
// Jangan hapus gambar di sini
|
|
|
|
return response()->json(['hasil' => $hasil, 'gambar' => $image_name]);
|
|
}
|
|
|
|
public function predictAngka(Request $request)
|
|
{
|
|
$request->validate([
|
|
'image' => 'required|image|mimes:jpeg,png,jpg|max:20000',
|
|
], [
|
|
'image.required' => 'Image is required!',
|
|
'image.image' => 'File must be an image!',
|
|
'image.mimes' => 'File must be jpeg, png, atau jpg!',
|
|
'image.max' => 'File size must be less than 20MB!',
|
|
]);
|
|
|
|
$image = $request->file('image');
|
|
$image_name = time() . '.' . $image->extension();
|
|
$image_path = public_path('images/angka/') . $image_name;
|
|
$image->move(public_path('images/angka/'), $image_name);
|
|
|
|
$response = Http::attach(
|
|
'image',
|
|
file_get_contents($image_path),
|
|
$image_name
|
|
)->post('https://jkgpolkesbaya.my.id/predict/angka');
|
|
|
|
$data = json_decode($response->body(), true);
|
|
$hasil = $data['prediction'];
|
|
|
|
// Jangan hapus gambar di sini
|
|
|
|
return response()->json(['hasil' => $hasil, 'gambar' => $image_name]);
|
|
}
|
|
|
|
public function predictHuruf(Request $request)
|
|
{
|
|
$request->validate([
|
|
'image' => 'required|image|mimes:jpeg,png,jpg|max:20000',
|
|
], [
|
|
'image.required' => 'Image is required!',
|
|
'image.image' => 'File must be an image!',
|
|
'image.mimes' => 'File must be jpeg, png, atau jpg!',
|
|
'image.max' => 'File size must be less than 20MB!',
|
|
]);
|
|
|
|
$image = $request->file('image');
|
|
$image_name = time() . '.' . $image->extension();
|
|
$image_path = public_path('images/huruf/') . $image_name;
|
|
$image->move(public_path('images/huruf/'), $image_name);
|
|
|
|
$response = Http::attach(
|
|
'image',
|
|
file_get_contents($image_path),
|
|
$image_name
|
|
)->post('https://jkgpolkesbaya.my.id/predict/huruf');
|
|
|
|
$data = json_decode($response->body(), true);
|
|
$hasil = $data['prediction'];
|
|
|
|
// Jangan hapus gambar di sini
|
|
|
|
return response()->json(['hasil' => $hasil, 'gambar' => $image_name]);
|
|
}
|
|
}
|