Spaces:
Running
Running
mhdiqbalpradipta
commited on
Commit
•
ff2d287
1
Parent(s):
03f7a50
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,22 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
from fastapi import FastAPI
|
4 |
|
5 |
-
#
|
6 |
food_classifier = pipeline(task="image-classification", model="mhdiqbalpradipta/minang_food_classification")
|
7 |
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
label_makanan = hasil['label']
|
15 |
-
skor = hasil['score']
|
16 |
-
|
17 |
-
return f"Makanan: {label_makanan}, Skor: {skor:.2f}"
|
18 |
-
|
19 |
-
# Antarmuka Gradio
|
20 |
image_in = gr.Image(type='pil')
|
21 |
label_out = "text"
|
22 |
-
|
23 |
-
|
24 |
-
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.")
|
25 |
-
|
26 |
-
# if __name__ == "__main__":
|
27 |
-
app = FastAPI()
|
28 |
-
|
29 |
-
@app.get('/')
|
30 |
-
async def root():
|
31 |
-
return 'Gradio app is running at /gradio', 200
|
32 |
|
33 |
-
|
34 |
-
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
+
# Load the model for food classification
|
5 |
food_classifier = pipeline(task="image-classification", model="mhdiqbalpradipta/minang_food_classification")
|
6 |
|
7 |
+
def predict_food(image):
|
8 |
+
# Perform prediction using the model
|
9 |
+
result = food_classifier(images=image)[0]
|
10 |
|
11 |
+
# Save label and score
|
12 |
+
food_label = result['label']
|
13 |
+
score = result['score']
|
14 |
+
return f"Food: {food_label}, Score: {score:.2f}"
|
15 |
|
16 |
+
# Gradio Interface
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
image_in = gr.Image(type='pil')
|
18 |
label_out = "text"
|
19 |
+
example_images = ['ayam_goreng.jpg', 'ayam_pop.jpg', 'daging_rendang.jpg', 'dendeng_batokok.jpg', 'gulai_ikan.jpg', 'gulai_tambusu.jpg', 'gulai_tunjang.jpg', 'telur_balado.jpg', 'telur_dadar.jpg']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
intf = gr.Interface(fn=predict_food, inputs=image_in, outputs=label_out, examples=example_images, title="Minang Food Classifier", description="Upload an image of food to classify it into Minang dishes.")
|
22 |
+
intf.launch(share=False);
|