Upload 2 files
Browse files- app.py +27 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
from huggingface_hub import from_pretrained_fastai
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
learn = from_pretrained_fastai("Pablogps/castle-classifier-24")
|
| 7 |
+
labels = learn.dls.vocab
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def predict(img):
|
| 11 |
+
img = PILImage.create(img)
|
| 12 |
+
pred, pred_idx, probs = learn.predict(img)
|
| 13 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
title = "Bad castle predictor"
|
| 17 |
+
description = "A bad model that tries to identify the type of castle."
|
| 18 |
+
examples = ['spanish', 'french', 'japanese']
|
| 19 |
+
|
| 20 |
+
gr.Interface(
|
| 21 |
+
fn=predict,
|
| 22 |
+
inputs=gr.Image(),
|
| 23 |
+
outputs=gr.Label(num_top_classes=3),
|
| 24 |
+
title=title,
|
| 25 |
+
description=description,
|
| 26 |
+
examples=examples,
|
| 27 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
timm
|
| 2 |
+
fastai
|
| 3 |
+
toml
|