sridiyer commited on
Commit
91e0ded
1 Parent(s): 3f3ad8a

new app file

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import datasets
3
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
4
+ import gradio as gr
5
+
6
+ dataset = datasets.load_dataset("beans")
7
+
8
+ extractor = AutoFeatureExtractor.from_pretrained("saved_model_files")
9
+ model = AutoModelForImageClassification.from_pretrained("saved_model_files")
10
+
11
+ labels = dataset['train'].features['labels'].names
12
+
13
+ def classify(im):
14
+ features = feature_extractor(im, return_tensors='pt')
15
+ logits = model(**features).logits
16
+ logits = torch.nn.functional.softmax(logits, dim=-1)
17
+ probability = torch.nn.functional.softmax(logits, dim=-1)
18
+ probs = probability[0].detach().numpy()
19
+ confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
20
+ return confidences
21
+
22
+ # following dummy till i figure out how to upload custom saved model
23
+
24
+ def classify1(im)
25
+ label = {'leaf spot' : 0.9, 'rust' : 0.1}
26
+ return label
27
+
28
+ interface = interface = gr.Interface(classify1, inputs='image', outputs='label', title='Leaf Classification demo',
29
+ description='Demo of fine-tuning a ViT for image classification based on the bean dataset classification') # FILL HERE
30
+
31
+ interface.launch()