3v324v23 commited on
Commit
a47ad99
·
1 Parent(s): 7475e40

Commit : 107

Browse files
Files changed (1) hide show
  1. app.py +19 -46
app.py CHANGED
@@ -1,54 +1,27 @@
1
- %pip install fastbook
2
 
3
- import gradio as gr
4
- from fastbook import *
5
-
6
-
7
- Search_Words = ["bird", "forest"]
8
- path = Path("images")
9
- Search_Num = 10
10
-
11
- for W in Search_Words:
12
- dest = path/W
13
- dest.mkdir(exist_ok=True, parents=True)
14
- download_images(dest, urls=search_images_ddg(f'{W} photo', max_images=Search_Num))
15
- time.sleep(5)
16
- resize_images(path/W, max_size=400, dest=path/W)
17
 
 
 
 
18
 
19
- dls = DataBlock(
20
- blocks=(ImageBlock, CategoryBlock),
21
- get_items=get_image_files,
22
- splitter=RandomSplitter(valid_pct=0.2, seed=42),
23
- get_y=parent_label,
24
- item_tfms=[Resize(192, method='squish')]
25
- ).dataloaders(path, bs=6)
26
-
27
-
28
- learn = vision_learner(dls, resnet18, metrics=error_rate)
29
- learn.fine_tune(3)
30
-
31
- def predict_image(image):
32
- img = PILImage.create(image)
33
- pred, pred_idx, probs = learn.predict(img)
34
- return pred
35
 
36
- # Create a Gradio interface with updated input/output methods
37
- iface = gr.Interface(
38
- fn=predict_image,
39
- inputs=gr.Image(), # Use gr.Image for input
40
- outputs=gr.Label(), # Use gr.Label and gr.Number for output
41
- examples=[
42
- ["Examples/1.jpg"],
43
- ["Examples/2.jpg"],
44
- ["Examples/3.jpg"],
45
- ["Examples/4.jpg"]
46
- ]
47
- )
48
 
49
- iface.launch()
 
50
 
 
 
 
51
 
 
 
 
 
52
 
53
- demo = gr.Interface(fn=prediction, inputs=image, outputs=label, examples=examples)
54
- demo.launch(inline = False)
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: . (unless otherwise specified).
2
 
3
+ __all__ = ['is_cat', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
+ # Cell
6
+ from fastai.vision.all import *
7
+ import gradio as gr
8
 
9
+ def is_cat(x): return x[0].isupper()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ # Cell
12
+ learn = load_learner('model.pkl')
 
 
 
 
 
 
 
 
 
 
13
 
14
+ # Cell
15
+ categories = ('Dog', 'Cat')
16
 
17
+ def classify_image(img):
18
+ pred,idx,probs = learn.predict(img)
19
+ return dict(zip(categories, map(float,probs)))
20
 
21
+ # Cell
22
+ image = gr.inputs.Image(shape=(192, 192))
23
+ label = gr.outputs.Label()
24
+ examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
25
 
26
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
27
+ intf.launch(inline=False)