DimasMP3 commited on
Commit
d2f7145
·
1 Parent(s): ec4fcee

fix gr.Label

Browse files
Files changed (1) hide show
  1. app.py +8 -27
app.py CHANGED
@@ -1,4 +1,5 @@
1
- # app.py
 
2
  import os
3
  import gradio as gr
4
  from inference import predict, predict_batch
@@ -6,24 +7,11 @@ from inference import predict, predict_batch
6
  APP_TITLE = "# Face Shape Classification — EfficientNetB4 (300×300)"
7
  APP_DESC = """
8
  **Model:** EfficientNetB4 (ImageNet) fine-tuned pada 5 kelas: **Heart, Oblong, Oval, Round, Square**.
9
- **Input:** Foto wajah **frontal** RGB (1 orang), di-resize otomatis ke **300×300**.
10
- **Output:** Prediksi kelas + confidence.
11
- **Catatan:** Untuk **penelitian/edukasi**, bukan untuk keputusan sensitif.
12
- """
13
- APP_FAQ = """
14
- ### FAQ
15
- - **Perlu normalisasi manual?** Tidak. Aplikasi menyesuaikan preprocessing internal model.
16
- - **Format gambar?** JPG/PNG, RGB.
17
- - **Privasi:** Gambar diproses saat inferensi dan tidak disimpan.
18
  """
19
 
20
- def _payload(d: dict):
21
- items = sorted(d.items(), key=lambda kv: kv[1], reverse=True)
22
- return {
23
- "label": items[0][0],
24
- "confidences": [{"label": k, "confidence": float(v)} for k, v in items],
25
- }
26
-
27
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
28
  gr.Markdown(APP_TITLE)
29
  gr.Markdown(APP_DESC)
@@ -31,25 +19,18 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
31
  with gr.Row():
32
  inp = gr.Image(type="pil", label="Upload face (frontal)")
33
  out = gr.Label(num_top_classes=5, label="Predictions")
 
34
  with gr.Row():
35
  btn = gr.Button("Predict", variant="primary")
36
  gr.ClearButton([inp, out])
37
- btn.click(lambda im: _payload(predict(im)), inputs=inp, outputs=out)
38
 
39
- with gr.Accordion("ℹ️ Detail & FAQ", open=False):
40
- gr.Markdown(APP_FAQ)
41
 
42
  with gr.Tab("Batch (optional)"):
43
- gal = gr.Gallery(label="Images", columns=4, height="auto")
44
  out_gal = gr.JSON(label="Batch outputs")
45
  runb = gr.Button("Run batch")
46
  runb.click(predict_batch, inputs=gal, outputs=out_gal)
47
 
48
- if os.path.exists("examples"):
49
- gr.Examples(
50
- examples=[os.path.join("examples", f) for f in os.listdir("examples")],
51
- inputs=inp
52
- )
53
-
54
  if __name__ == "__main__":
55
  demo.launch()
 
1
+ # app.py (potongan penting saja)
2
+
3
  import os
4
  import gradio as gr
5
  from inference import predict, predict_batch
 
7
  APP_TITLE = "# Face Shape Classification — EfficientNetB4 (300×300)"
8
  APP_DESC = """
9
  **Model:** EfficientNetB4 (ImageNet) fine-tuned pada 5 kelas: **Heart, Oblong, Oval, Round, Square**.
10
+ **Val Acc (best): ~96%** · **Input:** Foto wajah **frontal** RGB (1 orang), auto-resize **300×300**.
11
+ **Output:** Prediksi + confidence (Top-5).
12
+ **Disclaimer:** Untuk penelitian/edukasi.
 
 
 
 
 
 
13
  """
14
 
 
 
 
 
 
 
 
15
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
16
  gr.Markdown(APP_TITLE)
17
  gr.Markdown(APP_DESC)
 
19
  with gr.Row():
20
  inp = gr.Image(type="pil", label="Upload face (frontal)")
21
  out = gr.Label(num_top_classes=5, label="Predictions")
22
+
23
  with gr.Row():
24
  btn = gr.Button("Predict", variant="primary")
25
  gr.ClearButton([inp, out])
 
26
 
27
+ btn.click(predict, inputs=inp, outputs=out)
 
28
 
29
  with gr.Tab("Batch (optional)"):
30
+ gal = gr.Gallery(label="Images", columns=4, height="auto")
31
  out_gal = gr.JSON(label="Batch outputs")
32
  runb = gr.Button("Run batch")
33
  runb.click(predict_batch, inputs=gal, outputs=out_gal)
34
 
 
 
 
 
 
 
35
  if __name__ == "__main__":
36
  demo.launch()