Spaces:
Runtime error
Runtime error
Commit
·
0654cd1
1
Parent(s):
e97cff9
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,23 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
# Set gradio interface
|
| 4 |
gr_interface = gr.Interface(classify, inputs='image', outputs='label', title='Bean Classification', description='Monitor your crops health in easier way')
|
| 5 |
# Launch gradio
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import datasets
|
| 3 |
+
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
| 4 |
|
| 5 |
+
dataset = datasets.load_dataset('beans')
|
| 6 |
+
|
| 7 |
+
extractor = AutoFeatureExtractor.from_pretrained("saved_model_files")
|
| 8 |
+
model = AutoModelForImageClassification.from_pretrained("saved_model_files")
|
| 9 |
+
|
| 10 |
+
labels = dataset['train'].features['labels'].names
|
| 11 |
+
|
| 12 |
+
def classify(im):
|
| 13 |
+
features = feature_extractor(im, return_tensors='pt')
|
| 14 |
+
with torch.no_grad():
|
| 15 |
+
logits = model(features["pixel_values"])[-1]
|
| 16 |
+
probability = torch.nn.functional.softmax(logits, dim=-1)
|
| 17 |
+
probs = probability[0].detach().numpy()
|
| 18 |
+
confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
|
| 19 |
+
return confidences
|
| 20 |
+
|
| 21 |
# Set gradio interface
|
| 22 |
gr_interface = gr.Interface(classify, inputs='image', outputs='label', title='Bean Classification', description='Monitor your crops health in easier way')
|
| 23 |
# Launch gradio
|