Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,21 @@
|
|
1 |
-
from fastai.vision.all import *
|
2 |
import gradio as gr
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
#
|
8 |
-
labels = learn.dls.vocab
|
9 |
-
|
10 |
-
# 預測函式
|
11 |
-
def classify_image(img):
|
12 |
-
pred, idx, probs = learn.predict(img)
|
13 |
-
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
14 |
-
|
15 |
-
# 建立 Gradio 介面
|
16 |
demo = gr.Interface(
|
17 |
-
fn=
|
18 |
inputs=gr.Image(type="pil"),
|
19 |
outputs=gr.Label(num_top_classes=4),
|
20 |
-
title="
|
21 |
-
description="
|
22 |
)
|
23 |
|
24 |
-
|
25 |
-
demo.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
# 模擬預測函式(無模型,僅回傳固定結果)
|
4 |
+
def fake_predict(img):
|
5 |
+
return {
|
6 |
+
"女性醫護": 0.25,
|
7 |
+
"男性醫護": 0.25,
|
8 |
+
"女性工程師": 0.25,
|
9 |
+
"男性工程師": 0.25
|
10 |
+
}
|
11 |
|
12 |
+
# Gradio UI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
demo = gr.Interface(
|
14 |
+
fn=fake_predict,
|
15 |
inputs=gr.Image(type="pil"),
|
16 |
outputs=gr.Label(num_top_classes=4),
|
17 |
+
title="性別平等職業分類器",
|
18 |
+
description="(展示介面)上傳圖片,將模擬分類為:女性醫護、男性醫護、女性工程師、男性工程師。"
|
19 |
)
|
20 |
|
21 |
+
demo.launch()
|
|