Spaces:
Sleeping
Sleeping
socd06
commited on
Commit
·
788fbbb
1
Parent(s):
75a76fe
Add app.py and requirements.txt
Browse files- .idea/.gitignore +3 -0
- app.py +21 -0
- requirements.txt +2 -0
.idea/.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
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 |
+
|
9 |
+
|
10 |
+
def predict_fn(img):
|
11 |
+
"""
|
12 |
+
:param img: img is a PIL image object
|
13 |
+
:return: prediction and probabilities
|
14 |
+
"""
|
15 |
+
img = img.convert('RGB')
|
16 |
+
prediction, _, probs = learner.predict(img)
|
17 |
+
# print(f'{max(100 * probs):.2f}% {prediction} - {img}')
|
18 |
+
return f'{max(100 * probs):.2f}% {prediction} - {img}'
|
19 |
+
|
20 |
+
|
21 |
+
gr.Interface(predict_fn, gr.inputs.Image(type='pil'), outputs='label').launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
timm
|