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

fix AttributeError: 'Gallery

Browse files
Files changed (1) hide show
  1. app.py +32 -11
app.py CHANGED
@@ -1,29 +1,50 @@
1
  # app.py
2
  import os
3
  import gradio as gr
4
- from inference import predict, predict_batch # <-- gunakan fungsi dari inference.py
5
 
6
- def _payload(d):
7
- # ubah dict {label: prob} -> payload gradio.Label
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  items = sorted(d.items(), key=lambda kv: kv[1], reverse=True)
9
- return {"label": items[0][0], "confidences": [{"label": k, "confidence": float(v)} for k, v in items]}
 
 
 
10
 
11
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
12
- gr.Markdown("# Face Shape Classification — EfficientNetB4 (300×300)")
 
 
13
  with gr.Row():
14
  inp = gr.Image(type="pil", label="Upload face (frontal)")
15
  out = gr.Label(num_top_classes=5, label="Predictions")
16
- btn = gr.Button("Predict")
 
 
17
  btn.click(lambda im: _payload(predict(im)), inputs=inp, outputs=out)
18
 
19
- # Batch tab (opsional)
20
- with gr.Tab("Batch"):
21
- gal = gr.Gallery(label="Images").style(grid=4)
 
 
22
  out_gal = gr.JSON(label="Batch outputs")
23
  runb = gr.Button("Run batch")
24
- runb.click(lambda ims: [predict_batch(ims)], inputs=gal, outputs=out_gal)
25
 
26
- # Examples (jika ada folder examples/)
27
  if os.path.exists("examples"):
28
  gr.Examples(
29
  examples=[os.path.join("examples", f) for f in os.listdir("examples")],
 
1
  # app.py
2
  import os
3
  import gradio as gr
4
+ from inference import predict, predict_batch
5
 
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)
30
+
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")],