skalyan91 commited on
Commit
5dec542
·
1 Parent(s): cdc6900

Deploying model to HuggingFace Spaces

Browse files
Files changed (5) hide show
  1. app.py +35 -0
  2. requirements.txt +2 -0
  3. sans.gif +0 -0
  4. serif-sans.pkl +3 -0
  5. serif.gif +0 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ import gradio as gr
4
+ from fastai.vision.all import *
5
+ import skimage
6
+
7
+ learn = load_learner("serif-sans.pkl")
8
+
9
+ labels = learn.dls.vocab
10
+
11
+
12
+ def predict(img):
13
+ img = PILImage.create(img)
14
+ pred, pred_idx, probs = learn.predict(img)
15
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
16
+
17
+
18
+ title = "Font Classifier"
19
+ description = "A font classifier trained on images from identifont.com with fastai. Created as a project for Week 2 of the 2022 FastAI course."
20
+ article = "" # Use in case I write a blogpost about this.
21
+ examples = ["serif.gif", "sans.gif"]
22
+ interpretation = "default"
23
+ enable_queue = True
24
+
25
+ gr.Interface(
26
+ fn=predict,
27
+ inputs=gr.inputs.Image(shape=(512, 512)),
28
+ outputs=gr.outputs.Label(num_top_classes=1),
29
+ title=title,
30
+ description=description,
31
+ article=article,
32
+ examples=examples,
33
+ interpretation=interpretation,
34
+ enable_queue=enable_queue,
35
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastai
2
+ scikit-image
sans.gif ADDED
serif-sans.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9be943b9d45c13d1d1f91e7d4f3c82aabfa3812cb55640a69a6698d69d70f776
3
+ size 46958443
serif.gif ADDED