Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
from huggingface_hub import from_pretrained_fastai
|
| 4 |
+
|
| 5 |
+
import pathlib
|
| 6 |
+
plt = platform.system()
|
| 7 |
+
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
|
| 8 |
+
|
| 9 |
+
learn = from_pretrained_fastai(repo_id = "KathrynMercer/BoneClassifier")
|
| 10 |
+
|
| 11 |
+
labels = learn.dls.vocab
|
| 12 |
+
def predict(img):
|
| 13 |
+
img = PILImage.create(img)
|
| 14 |
+
pred,pred_idx,probs = learn.predict(img)
|
| 15 |
+
return {labels[i].title(): float(probs[i]) for i in range(len(labels))}
|
| 16 |
+
|
| 17 |
+
gr.Interface(fn=predict,
|
| 18 |
+
inputs='image',
|
| 19 |
+
outputs='label',
|
| 20 |
+
title = 'Human vs Nonhuman Long Bone Classifier',
|
| 21 |
+
description = ''A computer vision classifier to determine if an image of a bone is more likely human or non-human origin. Use at your own risk.',
|
| 22 |
+
examples = [[r'test images\test human femur - Swedish History Museum.jpg'],
|
| 23 |
+
interpretation='default').launch(share=True)
|