obrito commited on
Commit
d99fff9
·
1 Parent(s): 12a82a3

added the rest of the program

Browse files
Files changed (4) hide show
  1. .app.py.un~ +0 -0
  2. .requirements.txt.un~ +0 -0
  3. app.py +17 -0
  4. app.py~ +5 -0
.app.py.un~ DELETED
Binary file (1.39 kB)
 
.requirements.txt.un~ DELETED
Binary file (523 Bytes)
 
app.py CHANGED
@@ -1,4 +1,21 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  interface = gr.Interface(fn=classify, inputs="image", outputs="label")
4
 
 
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 = image_processor(im, return_tensors='pt')
14
+ logits = model(features["pixel_values"])[-1]
15
+ probability = torch.nn.functional.softmax(logits, dim=-1)
16
+ probs = probability[0].detach().numpy()
17
+ confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
18
+ return confidences
19
 
20
  interface = gr.Interface(fn=classify, inputs="image", outputs="label")
21
 
app.py~ ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ interface = gr.Interface(fn=classify, inputs="image", outputs="label")
4
+
5
+ interface.launch(debug=True)