wanghe commited on
Commit
c43f521
·
1 Parent(s): 5189b41
Files changed (2) hide show
  1. app.py +37 -13
  2. model (1).pkl → model_last.pkl +0 -0
app.py CHANGED
@@ -1,25 +1,49 @@
1
- import gradio as gr
2
  from fastai.vision.all import *
3
 
4
- def greet(name):
 
5
  return "Hello " + name + "!!"
6
 
7
- learn = load_learner("model.pkl");
8
 
9
  def is_cat(x): return x[0].isupper()
10
 
11
 
12
- categories = {"No_Cat","Cat"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  def classify_image(img):
14
- pred,idx,probs = learn.predict(img)
15
- return dict(zip(categories, map(float,probs)))
16
 
17
- image = gr.inputs.Image(shape=(192,192))
18
- label = gr.outputs.Label()
19
20
- intf = gr.Interface(fn=classify_image,inputs = image,outputs = label,examples = examples)
21
- intf.launch(inline=False)
22
 
 
 
 
 
 
 
23
 
24
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
25
- demo.launch()
 
1
+ import gradio
2
  from fastai.vision.all import *
3
 
4
+
5
+ def gradioeet(name):
6
  return "Hello " + name + "!!"
7
 
 
8
 
9
  def is_cat(x): return x[0].isupper()
10
 
11
 
12
+ # path = untar_data(URLs.DOGS) / 'images'
13
+ # dls = ImageDataLoaders.from_name_func('.',
14
+ # get_image_files(path), valid_pct=0.2, seed=42,
15
+ # label_func=is_cat,
16
+ # item_tfms=Resize(192))
17
+ #
18
+ # dls.valid.show_batch(max_n=4, nrows=1)
19
+ #
20
+
21
+ #
22
+ # learn = vision_learner(dls, resnet18, metrics=error_rate)
23
+ # learn.fine_tune(3)
24
+
25
+ # interp = ClassificationInterpretation.from_learner(learn)
26
+ # interp.plot_confusion_matrix()
27
+ #
28
+ # learn.export('model2.pkl')
29
+
30
+
31
+ learn = load_learner("model_last.pkl")
32
+
33
+ categories = {"No_Cat", "Cat"}
34
+
35
+
36
  def classify_image(img):
37
+ pred, idx, probs = learn.predict(img)
38
+ return dict(zip(categories, map(float, probs)))
39
 
 
 
 
 
 
40
 
41
+ image = gradio.Image(height=192, width=192)
42
+ label = gradio.Label()
43
44
45
+ intf = gradio.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
46
+ intf.launch(inline=False)
47
 
48
+ # demo = gradio.Interface(fn=gradioeet, inputs="text", outputs="text")
49
+ # demo.launch(inline=False)
model (1).pkl → model_last.pkl RENAMED
File without changes