Spaces:
Runtime error
Runtime error
add implementation/interface
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
4 |
+
|
5 |
+
def classify(im):
|
6 |
+
features = feature_extractor(im, return_tensors='pt')
|
7 |
+
logits = model(features['pixel_values'])[-1]
|
8 |
+
probability = torch.nn.functional.softmax(logits, dim=-1)
|
9 |
+
probs = probability[0].detach().numpy()
|
10 |
+
confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
|
11 |
+
return confidences
|
12 |
+
|
13 |
+
dataset = datasets.load_dataset('beans', 'full_size')
|
14 |
+
|
15 |
+
extractor = AutoFeatureExtractor.from_pretrained('saved_model_files')
|
16 |
+
model = AutoModelForImageClassification.from_pretrained('saved_model_files')
|
17 |
+
|
18 |
+
labels = dataset['train'].features['labels'].names
|
19 |
+
|
20 |
+
interface = gr.Interface(fn=classify, inputs=gr.Image(shape=(200, 200)), outputs=gr.outputs.Label(num_top_classes=3),
|
21 |
+
examples=['leaf1.png', 'leaf2.png'], title='Leaf Classification App', description='Check if the leaves of your plant are healthy!', flagging_dir='flagged_examples/')
|
22 |
+
|
23 |
+
interface.launch(debug=True)
|
leaf1.png
ADDED
leaf2.png
ADDED
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
torch
|