Spaces:
Sleeping
Sleeping
Update : Add Labels
Browse files
app.py
CHANGED
|
@@ -4,6 +4,16 @@ import numpy as np
|
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
model = tf.keras.models.load_model("best_model_mobilenetv2_finetune.h5")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def process(img):
|
| 9 |
img = img.resize((224,224))
|
|
@@ -14,7 +24,9 @@ def predict(img):
|
|
| 14 |
img = process(img)
|
| 15 |
pred = model.predict(img)
|
| 16 |
class_idx = np.argmax(pred)
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
interface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"),outputs="text")
|
| 20 |
interface.launch()
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
model = tf.keras.models.load_model("best_model_mobilenetv2_finetune.h5")
|
| 7 |
+
class_labels = [
|
| 8 |
+
'ayam bakar','ayam goreng','bakso','bakwan',
|
| 9 |
+
'bihun','capcay','gado-gado','ikan goreng',
|
| 10 |
+
'kerupuk', 'martabak telur','mie','nasi goreng',
|
| 11 |
+
'nasi putih','nugget','opor ayam','pempek',
|
| 12 |
+
'rendang','roti','sate','sosis',
|
| 13 |
+
'soto','tahu','telur','tempe',
|
| 14 |
+
'tumis kangkung',
|
| 15 |
+
'udang',
|
| 16 |
+
]
|
| 17 |
|
| 18 |
def process(img):
|
| 19 |
img = img.resize((224,224))
|
|
|
|
| 24 |
img = process(img)
|
| 25 |
pred = model.predict(img)
|
| 26 |
class_idx = np.argmax(pred)
|
| 27 |
+
confidence = pred[0][class_idx]
|
| 28 |
+
class_name = class_labels[class_idx]
|
| 29 |
+
return f"{class_name} (confidence: {confidence:.2f})"
|
| 30 |
|
| 31 |
interface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"),outputs="text")
|
| 32 |
interface.launch()
|