Jesse Alter commited on
Commit
4604714
1 Parent(s): c3dc4b3

add missing pieces

Browse files
Files changed (2) hide show
  1. app.py +28 -18
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,25 +1,18 @@
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: os_identify.ipynb.
2
 
3
  # %% auto 0
4
- __all__ = ['btn_upload', 'btn_run', 'path', 'learn_inf', 'out_pl', 'lbl_pred', 'on_click_classify']
 
5
 
6
  # %% os_identify.ipynb 4
7
  from fastai.vision.all import *
8
- from fastai.vision.widgets import *
9
  import gradio as gr
10
 
11
- # %% os_identify.ipynb 5
12
- def on_click_classify(change):
13
- img = PILImage.create(btn_upload.data[-1])
14
- out_pl.clear_output()
15
- with out_pl: display(img.to_thumb(128,128))
16
- pred,pred_idx,probs = learn_inf.predict(btn_upload.data[-1])
17
- lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
18
-
19
  # %% os_identify.ipynb 6
20
- btn_upload = widgets.FileUpload()
21
- btn_run = widgets.Button(description='Classify')
22
- btn_run.on_click(on_click_classify)
23
 
24
  # %% os_identify.ipynb 7
25
  # load the model
@@ -27,11 +20,28 @@ path = Path()
27
  learn_inf = load_learner(path/'os_model.pkl')
28
 
29
  # %% os_identify.ipynb 8
30
- out_pl = widgets.Output()
31
- out_pl.clear_output()
32
- lbl_pred = widgets.Label()
33
 
34
 
35
  # %% os_identify.ipynb 9
36
- VBox([widgets.Label('Select your screencap!'),
37
- btn_upload, btn_run, out_pl, lbl_pred])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: os_identify.ipynb.
2
 
3
  # %% auto 0
4
+ __all__ = ['path', 'learn_inf', 'title', 'description', 'article', 'examples', 'interpretation', 'enable_queue', 'labels',
5
+ 'predict']
6
 
7
  # %% os_identify.ipynb 4
8
  from fastai.vision.all import *
9
+ # from fastai.vision.widgets import *
10
  import gradio as gr
11
 
 
 
 
 
 
 
 
 
12
  # %% os_identify.ipynb 6
13
+ # btn_upload = widgets.FileUpload()
14
+ # btn_run = widgets.Button(description='Classify')
15
+ # btn_run.on_click(on_click_classify)
16
 
17
  # %% os_identify.ipynb 7
18
  # load the model
 
20
  learn_inf = load_learner(path/'os_model.pkl')
21
 
22
  # %% os_identify.ipynb 8
23
+ # out_pl = widgets.Output()
24
+ # out_pl.clear_output()
25
+ # lbl_pred = widgets.Label()
26
 
27
 
28
  # %% os_identify.ipynb 9
29
+ # VBox([widgets.Label('Select your screencap!'),
30
+ # btn_upload, btn_run, out_pl, lbl_pred])
31
+
32
+ # %% os_identify.ipynb 10
33
+ title = "Operating System Screencap Classifier"
34
+ description = "A classifier trained on various operating system screenshots. For better results, use screenshots that clearly show unique UI elements. For best results, help me better a better dataset."
35
+ article="<p>article goes here</p>"
36
+ examples=['win95.jpg']
37
+ interpretation="default"
38
+ enable_queue=True
39
+
40
+ # %% os_identify.ipynb 11
41
+ labels = learn_inf.dls.vocab
42
+ def predict(img):
43
+ # img = PILImage.create(img)
44
+ pred,pred_idx,probs = learn_inf.predict(img)
45
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
46
+ gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch(share=True)
47
+ # gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  fastai
2
  gradio
 
 
1
  fastai
2
  gradio
3
+ scikit-image