Spaces:
Running
Running
mhdiqbalpradipta
commited on
Commit
•
0499d90
1
Parent(s):
e0edd9a
create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Memuat model untuk klasifikasi makanan
|
6 |
+
food_classifier = pipeline(task="image-classification", model="mhdiqbalpradipta/minang_food_classification")
|
7 |
+
|
8 |
+
def prediksi_makanan(gambar):
|
9 |
+
# Melakukan prediksi menggunakan model
|
10 |
+
hasil = food_classifier(images=gambar)[0]
|
11 |
+
|
12 |
+
# Menyimpan label dan skor
|
13 |
+
label_makanan = hasil['label']
|
14 |
+
skor = hasil['score']
|
15 |
+
|
16 |
+
return f"Makanan: {label_makanan}, Skor: {skor:.2f}"
|
17 |
+
|
18 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
19 |
+
print(f"Menggunakan perangkat: {device}")
|
20 |
+
|
21 |
+
# Antarmuka Gradio
|
22 |
+
image_in = gr.inputs.Image(type='pil')
|
23 |
+
label_out = gr.outputs.Label()
|
24 |
+
contoh_gambar = ['ayam_goreng.jpg', 'ayam_pop.jpg', 'daging_rendang.jpg', 'dendeng_batokok.jpg', 'gulai_ikan.jpg', 'gulai_tambusu.jpg', 'gulai_tunjang', 'telur_balado.jpg', 'telur_dadar.jpg']
|
25 |
+
|
26 |
+
intf = gr.Interface(fn=prediksi_makanan, inputs=image_in, outputs=label_out, examples=contoh_gambar, title="Pengklasifikasi Makanan Minang", description="Unggah gambar makanan untuk mengklasifikasikannya menjadi hidangan Minang.", live=True)
|
27 |
+
intf.launch()
|