onegoodlad commited on
Commit
10e6345
·
1 Parent(s): 8a36595

Launch human or animal application with 2 models

Browse files
Files changed (2) hide show
  1. app.py +20 -5
  2. requirements.txt +2 -0
app.py CHANGED
@@ -1,9 +1,24 @@
1
- # Default hello world app.
2
 
3
  import gradio as gr
 
 
4
 
5
- def greet(name):
6
- return "Hello " + name + "!!"
7
 
8
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
9
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Human or Animal application in gradio.
2
 
3
  import gradio as gr
4
+ from fastai.vision.all import *
5
+ import skimage
6
 
7
+ loaded_generic_model = load_learner('model_generic.pkl')
8
+ loaded_special_model = load_learner('model_special.pkl')
9
 
10
+ def label_func(filename):
11
+ if 'human' in Path(filename).parts[-2]:
12
+ return 'human'
13
+ elif 'animal' in Path(filename).parts[-2]:
14
+ return 'animal'
15
+
16
+ def predict_human_or_animal(img):
17
+ im = PILImage.create(img)
18
+ generic_class, generic_class_id, generic_probs = loaded_generic_model.predict(img)
19
+ #special_class, special_class_id, special_probs = loaded_special_model.predict(img)
20
+
21
+ return {generic_class: 1.0}
22
+
23
+ intf = gr.Interface(fn=predict_human_or_animal, inputs="image", outputs="label").launch()
24
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastai
2
+ scikit-image