sechelc commited on
Commit
75a7667
1 Parent(s): 0f3c929

let's deploy to huggingface spaces

Browse files
Files changed (3) hide show
  1. export.pkl +3 -0
  2. gradio_nsfw_classfier.py +22 -0
  3. requirments.txt +2 -0
export.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0382190a4647381f027bc601c2379c9a1b0616fccb26934cfede376329b2985d
3
+ size 103946124
gradio_nsfw_classfier.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+ from fastai.vision.all import *
4
+ import gradio as gr
5
+
6
+ learn = load_learner('export.pkl')
7
+ labels = learn.dls.vocab
8
+
9
+ def predict(img):
10
+ img = PILImage.create(img)
11
+ pred,pred_idx,probs = learn.predict(img)
12
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
13
+
14
+
15
+ title = "NSFW image classifier"
16
+ description = "A nsfw image classifier trained on the nsfw_data_scraper dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
17
+ interpretation='default'
18
+ enable_queue=True
19
+
20
+ gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512,512)),outputs=gr.outputs.Label(num_top_classes=5),title=title,description=description,interpretation=interpretation,enable_queue=enable_queue).launch(share=True)
21
+
22
+
requirments.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastai
2
+ scikit-image