Spaces:
Sleeping
Sleeping
socd06
commited on
Commit
·
c151ed3
1
Parent(s):
120e91e
call secret IAW docs
Browse files
app.py
CHANGED
@@ -2,11 +2,12 @@ import os
|
|
2 |
from huggingface_hub import from_pretrained_fastai
|
3 |
|
4 |
import gradio as gr
|
|
|
5 |
|
|
|
6 |
repo_id = "artificeresearch/spiritvision"
|
7 |
-
learner = from_pretrained_fastai(repo_id)
|
8 |
labels = learner.dls.vocab
|
9 |
-
HF_TOKEN = os.environ.get("HF_TOKEN")
|
10 |
|
11 |
|
12 |
def predict_fn(img):
|
@@ -14,12 +15,11 @@ def predict_fn(img):
|
|
14 |
:param img: img is a PIL image object
|
15 |
:return: prediction and probabilities
|
16 |
"""
|
17 |
-
img = img.convert('RGB')
|
18 |
-
# print(f'{max(100 * probs):.2f}% {prediction} - {img}')
|
19 |
pred, pred_idx, probs = learner.predict(img)
|
20 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
21 |
|
22 |
|
23 |
gr.Interface(predict_fn,
|
24 |
-
|
25 |
-
outputs=gr.outputs.Label(num_top_classes=3),
|
|
|
|
2 |
from huggingface_hub import from_pretrained_fastai
|
3 |
|
4 |
import gradio as gr
|
5 |
+
from gradio.components import Image
|
6 |
|
7 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
8 |
repo_id = "artificeresearch/spiritvision"
|
9 |
+
learner = from_pretrained_fastai(repo_id, token=HF_TOKEN)
|
10 |
labels = learner.dls.vocab
|
|
|
11 |
|
12 |
|
13 |
def predict_fn(img):
|
|
|
15 |
:param img: img is a PIL image object
|
16 |
:return: prediction and probabilities
|
17 |
"""
|
|
|
|
|
18 |
pred, pred_idx, probs = learner.predict(img)
|
19 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
20 |
|
21 |
|
22 |
gr.Interface(predict_fn,
|
23 |
+
Image(shape=(512, 512)),
|
24 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
25 |
+
token=HF_TOKEN).launch()
|