erenska commited on
Commit
4de1a88
·
1 Parent(s): 6993e79

new file: app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #|default_exp app
2
+ !pip install gradio
3
+
4
+ # %% [code] {"execution":{"iopub.status.busy":"2023-01-17T14:41:33.341222Z","iopub.execute_input":"2023-01-17T14:41:33.341652Z","iopub.status.idle":"2023-01-17T14:41:34.776787Z","shell.execute_reply.started":"2023-01-17T14:41:33.341595Z","shell.execute_reply":"2023-01-17T14:41:34.775663Z"}}
5
+ #|export
6
+ from fastai.vision.all import *
7
+ import gradio as gr
8
+
9
+ # %% [code] {"execution":{"iopub.status.busy":"2023-01-17T14:43:57.890571Z","iopub.execute_input":"2023-01-17T14:43:57.891069Z","iopub.status.idle":"2023-01-17T14:43:58.607922Z","shell.execute_reply.started":"2023-01-17T14:43:57.891028Z","shell.execute_reply":"2023-01-17T14:43:58.606710Z"}}
10
+ #|export
11
+ learn = load_learner('/minima/model.pkl')
12
+
13
+ # %% [code] {"execution":{"iopub.status.busy":"2023-01-17T14:45:36.880658Z","iopub.execute_input":"2023-01-17T14:45:36.881241Z","iopub.status.idle":"2023-01-17T14:45:36.890302Z","shell.execute_reply.started":"2023-01-17T14:45:36.881102Z","shell.execute_reply":"2023-01-17T14:45:36.889172Z"}}
14
+ labels = learn.dls.vocab
15
+ def predict(img):
16
+ img = PILImage.create(img)
17
+ pred,pred_idx,probs = learn.predict(img)
18
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
19
+
20
+ # %% [code] {"execution":{"iopub.status.busy":"2023-01-17T14:46:08.717339Z","iopub.execute_input":"2023-01-17T14:46:08.717913Z","iopub.status.idle":"2023-01-17T14:46:15.759750Z","shell.execute_reply.started":"2023-01-17T14:46:08.717858Z","shell.execute_reply":"2023-01-17T14:46:15.758401Z"}}
21
+ gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)