Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
pkl = os.path.dirname(__file__)/Path("all_20210912_res34.pkl")
|
| 5 |
+
from fastai.vision.all import *
|
| 6 |
+
from fastai.vision.widgets import *
|
| 7 |
+
import jaconv
|
| 8 |
+
model_inf = load_learner(pkl)
|
| 9 |
+
print(os.getcwd())
|
| 10 |
+
def kinoko_uranai(img):
|
| 11 |
+
replace_dic = {"_ッロウッ":" (group)","ー":""}
|
| 12 |
+
result_dic = {}
|
| 13 |
+
pred_class, pred_idxs, outputs = model_inf.predict(img)
|
| 14 |
+
top_5_conf, i = outputs.topk(5)
|
| 15 |
+
itr = 0
|
| 16 |
+
classes = model_inf.dls.vocab
|
| 17 |
+
result_dic = {}
|
| 18 |
+
for x in i:
|
| 19 |
+
kwamei = jaconv.alphabet2kata(classes[x.item()].lower())
|
| 20 |
+
for k,v in replace_dic.items():
|
| 21 |
+
kwamei = kwamei.replace(k,v)
|
| 22 |
+
result_dic[kwamei] = str(round(top_5_conf[itr].item(),2))
|
| 23 |
+
itr=itr+1
|
| 24 |
+
return result_dic
|
| 25 |
+
outputs = gr.outputs.Label(num_top_classes=5)
|
| 26 |
+
iface = gr.Interface(fn=kinoko_uranai, inputs="image", outputs=outputs).launch(debug=True)
|