Spaces:
Build error
Build error
updated demo to include 50 classes
Browse files- app.ipynb +0 -0
- app.py +40 -21
- flagged/Binomial/tmphs9nl929.json +1 -0
- flagged/img/tmp0o3vkpoo.jpg +0 -0
- flagged/log.csv +2 -0
- requirements.txt +4 -1
- species_to_country_mapping.csv +0 -0
app.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
app.py
CHANGED
@@ -1,53 +1,72 @@
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
-
__all__ = ['repo_id', 'learner', 'path', 'categories', 'title', 'description', 'article', 'image', 'label',
|
5 |
-
'classify_image']
|
6 |
|
7 |
-
# %% app.ipynb
|
8 |
from fastai.vision.all import *
|
9 |
from huggingface_hub import from_pretrained_fastai
|
10 |
import gradio as gr
|
|
|
|
|
11 |
|
12 |
-
# %% app.ipynb
|
13 |
-
repo_id = "Jimmie/snake-
|
14 |
|
15 |
# loading the model from huggingface_hub
|
16 |
learner = from_pretrained_fastai(repo_id)
|
17 |
|
18 |
-
# %% app.ipynb
|
19 |
path = Path('demo-images/')
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
categories = tuple(learner.dls.vocab)
|
23 |
|
24 |
def classify_image(img):
|
25 |
pred,idx,probs = learner.predict(img)
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
-
# %% app.ipynb
|
29 |
-
title = "Snake
|
30 |
|
31 |
description = """
|
32 |
-
This demo is an ongoing iteration of
|
33 |
|
34 |
-
Currently, it can classify snakes into
|
35 |
|
36 |
-
The model can be found here: https://huggingface.co/Jimmie/snake-
|
37 |
-
|
38 |
|
39 |
Enjoy!
|
40 |
"""
|
41 |
|
42 |
-
article = "Blog posts on how the model is being trained:
|
43 |
|
44 |
|
45 |
-
image = gr.
|
46 |
-
label = gr.
|
|
|
|
|
|
|
47 |
examples = list(path.ls())
|
48 |
|
49 |
|
50 |
-
intf = gr.Interface(fn=classify_image, inputs=image,
|
51 |
-
|
52 |
-
|
|
|
53 |
intf.launch(inline=False)
|
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
+
__all__ = ['repo_id', 'learner', 'path', 'countries', 'categories', 'title', 'description', 'article', 'image', 'label',
|
5 |
+
'country', 'summary', 'link', 'examples', 'intf', 'get_countries', 'classify_image']
|
6 |
|
7 |
+
# %% app.ipynb 3
|
8 |
from fastai.vision.all import *
|
9 |
from huggingface_hub import from_pretrained_fastai
|
10 |
import gradio as gr
|
11 |
+
import wikipedia
|
12 |
+
import pandas as pd
|
13 |
|
14 |
+
# %% app.ipynb 4
|
15 |
+
repo_id = "Jimmie/snake-species-identification"
|
16 |
|
17 |
# loading the model from huggingface_hub
|
18 |
learner = from_pretrained_fastai(repo_id)
|
19 |
|
20 |
+
# %% app.ipynb 5
|
21 |
path = Path('demo-images/')
|
22 |
+
countries = pd.read_csv('species_to_country_mapping.csv', index_col=0)
|
23 |
+
|
24 |
+
# %% app.ipynb 9
|
25 |
+
def get_countries(binomial):
|
26 |
+
sample_row = countries.loc[binomial]
|
27 |
+
country_list = sample_row[sample_row == 1].index.tolist()
|
28 |
+
# title case all items in country_list
|
29 |
+
country_list = [country.title() for country in country_list]
|
30 |
+
# return all items in country_list as a string
|
31 |
+
return ", ".join(country_list)
|
32 |
+
|
33 |
+
# %% app.ipynb 20
|
34 |
categories = tuple(learner.dls.vocab)
|
35 |
|
36 |
def classify_image(img):
|
37 |
pred,idx,probs = learner.predict(img)
|
38 |
+
countries = get_countries(pred)
|
39 |
+
summary = wikipedia.summary(pred)
|
40 |
+
wiki_link = f"Learn more: <a href={wikipedia.page(pred).url}>{pred}</a>"
|
41 |
+
return dict(zip(categories, map(float, probs))), countries, summary, wiki_link
|
42 |
|
43 |
+
# %% app.ipynb 22
|
44 |
+
title = "Snake Species Identification"
|
45 |
|
46 |
description = """
|
47 |
+
This demo is an ongoing iteration of the [Snake Species Identification](https://github.com/jimmiemunyi/the-snake-project-cls) project meant to classify snakes up to the species level (binomial name).
|
48 |
|
49 |
+
Currently, it can classify snakes into 50 categories but it is continually updated to support more categories (over 200).
|
50 |
|
51 |
+
The model can be found here: https://huggingface.co/Jimmie/snake-species-identification.
|
52 |
+
The model is trained on the following dataset: https://www.aicrowd.com/challenges/snakeclef2021-snake-species-identification-challenge.
|
53 |
|
54 |
Enjoy!
|
55 |
"""
|
56 |
|
57 |
+
article = "Blog posts on how the model is being trained: COMING SOON!"
|
58 |
|
59 |
|
60 |
+
image = gr.Image(shape=(224, 224))
|
61 |
+
label = gr.Label(num_top_classes=3, label='Binomial')
|
62 |
+
country = gr.Textbox(label='Countries where the species is found')
|
63 |
+
summary = gr.Textbox(label='Wikipedia Summary')
|
64 |
+
link = gr.HTML(label="Learn More:", show_label=True)
|
65 |
examples = list(path.ls())
|
66 |
|
67 |
|
68 |
+
intf = gr.Interface(fn=classify_image, inputs=image,
|
69 |
+
outputs=[label, country, summary, link], examples=examples,
|
70 |
+
title = title, description = description, article = article,
|
71 |
+
cache_examples=False)
|
72 |
intf.launch(inline=False)
|
flagged/Binomial/tmphs9nl929.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"label": "Crotalus horridus", "confidences": [{"label": "Crotalus horridus", "confidence": 0.999326229095459}, {"label": "Pantherophis spiloides", "confidence": 0.00014710254617966712}, {"label": "Pantherophis alleghaniensis", "confidence": 5.688565943273716e-05}]}
|
flagged/img/tmp0o3vkpoo.jpg
ADDED
flagged/log.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
img,Binomial,Summary,flag,username,timestamp
|
2 |
+
/home/eleven/code/personal/snake-image-classification/flagged/img/tmp0o3vkpoo.jpg,/home/eleven/code/personal/snake-image-classification/flagged/Binomial/tmphs9nl929.json,"The timber rattlesnake, canebrake rattlesnake, or banded rattlesnake (Crotalus horridus) is a species of pit viper endemic to eastern North America. Like all other pit vipers, it is venomous, with a very toxic bite. C. horridus is the only rattlesnake species in most of the populous Northeastern United States and is second only to its relatives to the west, the prairie rattlesnake, as the most northerly distributed venomous snake in North America. No subspecies are currently recognized.",,,2023-03-27 07:54:18.071444
|
requirements.txt
CHANGED
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
1 |
fastai<=2.7.11
|
2 |
timm==0.8.3dev0
|
3 |
-
git+https://github.com/jimmiemunyi/the-snake-project@main#egg=the-snake-project
|
|
|
1 |
+
wikipedia==1.4.0
|
2 |
+
pandas==1.5.2
|
3 |
+
toml==0.10.2
|
4 |
fastai<=2.7.11
|
5 |
timm==0.8.3dev0
|
6 |
+
git+https://github.com/jimmiemunyi/the-snake-project@main#egg=the-snake-project
|
species_to_country_mapping.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|