nakranivaibhav commited on
Commit
4acf485
·
1 Parent(s): 83f183a

update .gitattributes so git lfs will track .pkl files

Browse files
Files changed (2) hide show
  1. app.py +17 -5
  2. model.pkl +3 -0
app.py CHANGED
@@ -1,9 +1,21 @@
1
  #%%
2
  import gradio as gr
 
3
 
4
- def greet(name):
5
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
6
 
7
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
8
- iface.launch()
9
- # %%
 
 
 
 
1
  #%%
2
  import gradio as gr
3
+ from fastai.vision.all import *
4
 
5
+ learn_inf = load_learner('model.pkl')
6
+ #%%
7
+ features = learn_inf.dls.vocab
8
+ #%%
9
+ def predict_image(image):
10
+ pred_class, pred_idx, probs = learn_inf.predict(image)
11
+ return {str(features[i]): float(probs[i]) for i in range(len(learn_inf.dls.vocab))}
12
+
13
+ input_image = gr.inputs.Image(shape=(None, None))
14
+ output_label = gr.outputs.Label(num_top_classes=3)
15
 
16
+ gr.Interface(fn=predict_image,
17
+ inputs=input_image,
18
+ outputs=output_label,
19
+ title="Image Classifier",
20
+ description=f"Upload an image to classify it into one of the following categories: {' | '.join([f'{item}' for item in features])}",
21
+ capture_session=True).launch()
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:223338e7345c9f0f5b35ee280104cc1029b901a81520abaae1f52b106ce72ebd
3
+ size 47019183