Spaces:
Runtime error
Runtime error
Add application file
Browse files- .gitattributes +8 -0
- app.py +42 -0
- examples/example_1.jpg +3 -0
- examples/example_2.jpg +3 -0
- examples/example_3.jpg +3 -0
- examples/example_4.jpg +3 -0
- examples/example_5.jpg +3 -0
- examples/example_6.jpg +3 -0
- examples/example_7.jpg +3 -0
- examples/example_9.jpg +3 -0
.gitattributes
CHANGED
|
@@ -25,3 +25,11 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 26 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
| 27 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 26 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
| 27 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
examples/example_1.jpg filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
examples/example_2.jpg filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
examples/example_3.jpg filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
examples/example_4.jpg filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
examples/example_5.jpg filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
examples/example_6.jpg filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
examples/example_7.jpg filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
examples/example_9.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from huggingface_hub import from_pretrained_fastai
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def get_x(x):
|
| 10 |
+
return pascal_source/"train"/f'{x[0]}'
|
| 11 |
+
|
| 12 |
+
def get_y(x):
|
| 13 |
+
return x[1].split(' ')
|
| 14 |
+
|
| 15 |
+
pascal_source = '.'
|
| 16 |
+
EXAMPLES_PATH = Path('./examples')
|
| 17 |
+
repo_id = "hugginglearners/identify-pascal"
|
| 18 |
+
|
| 19 |
+
learner = from_pretrained_fastai(repo_id)
|
| 20 |
+
labels = learner.dls.vocab
|
| 21 |
+
|
| 22 |
+
def infer(img):
|
| 23 |
+
img = PILImage.create(img)
|
| 24 |
+
_pred, _pred_w_idx, probs = learner.predict(img)
|
| 25 |
+
# gradio doesn't support tensors, so converting to float
|
| 26 |
+
labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
|
| 27 |
+
return labels_probs
|
| 28 |
+
# return f"This grapevine leave is {_pred} with {100*probs[torch.argmax(probs)].item():.2f}% probability"
|
| 29 |
+
|
| 30 |
+
# get the inputs
|
| 31 |
+
inputs = gr.inputs.Image(shape=(192, 192))
|
| 32 |
+
|
| 33 |
+
# the app outputs two segmented images
|
| 34 |
+
output = gr.outputs.Label(num_top_classes=3)
|
| 35 |
+
# it's good practice to pass examples, description and a title to guide users
|
| 36 |
+
title = 'Multilabel Image classification'
|
| 37 |
+
description = 'Detect which type of object appearing in the image'
|
| 38 |
+
article = "Author: <a href=\"https://huggingface.co/geninhu\">Nhu Hoang</a>. "
|
| 39 |
+
examples = [f'{EXAMPLES_PATH}/{f.name}' for f in EXAMPLES_PATH.iterdir()]
|
| 40 |
+
|
| 41 |
+
gr.Interface(infer, inputs, output, examples= examples, allow_flagging='never',
|
| 42 |
+
title=title, description=description, article=article, live=False).launch(enable_queue=True, debug=False, inbrowser=False)
|
examples/example_1.jpg
ADDED
|
Git LFS Details
|
examples/example_2.jpg
ADDED
|
Git LFS Details
|
examples/example_3.jpg
ADDED
|
Git LFS Details
|
examples/example_4.jpg
ADDED
|
Git LFS Details
|
examples/example_5.jpg
ADDED
|
Git LFS Details
|
examples/example_6.jpg
ADDED
|
Git LFS Details
|
examples/example_7.jpg
ADDED
|
Git LFS Details
|
examples/example_9.jpg
ADDED
|
Git LFS Details
|