Spaces:
Sleeping
Sleeping
added app
Browse files- app.py +34 -0
- example_images/car.jpeg +3 -0
- example_images/saturn.jpeg +3 -0
- model_params/planet_cls_1.pkl +3 -0
- planet_classifier.ipynb +0 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
|
4 |
+
# Define the main prediction function:
|
5 |
+
learn = load_learner('./model_params/planet_cls_1.pkl')
|
6 |
+
labels = learn.dls.vocab
|
7 |
+
def planet_classifier_predict(img) -> str:
|
8 |
+
img = PILImage.create(img)
|
9 |
+
_, _, probs = learn.predict(img)
|
10 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
11 |
+
|
12 |
+
|
13 |
+
if __name__ == "__main__":
|
14 |
+
# General web app params:
|
15 |
+
title = "Planet Classifier Demo"
|
16 |
+
description = "Let's say you want to classify a picture if it is one of the 9 planets: \
|
17 |
+
Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune. \
|
18 |
+
You can do it using this awesome tool!!!! Try it :)"
|
19 |
+
article = "<p style='text-align: center'><a href='https://www.tanishq.ai/blog/posts/2021-11-16-gradio-huggingface.html' target='_blank'>The main source of inspiration :) </a></p>"
|
20 |
+
examples = ['./example_images/saturn.jpeg', './example_images/car.jpeg']
|
21 |
+
interpretation = 'default'
|
22 |
+
enable_queue = True
|
23 |
+
inputs = "image"
|
24 |
+
outputs = "label"
|
25 |
+
# The main app interface:
|
26 |
+
gr.Interface(
|
27 |
+
fn=planet_classifier_predict,
|
28 |
+
inputs=inputs,
|
29 |
+
outputs=outputs,
|
30 |
+
title=title,
|
31 |
+
description=description,
|
32 |
+
article=article,
|
33 |
+
examples=examples,
|
34 |
+
).launch()
|
example_images/car.jpeg
ADDED
![]() |
Git LFS Details
|
example_images/saturn.jpeg
ADDED
![]() |
Git LFS Details
|
model_params/planet_cls_1.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ecb82741ed90a93ac87fb4e57dfd2a2c1895f210620feb538c7f22361d1f7dc3
|
3 |
+
size 46996647
|
planet_classifier.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
fastai
|