Nithila Ariyapperuma commited on
Commit
81e469f
1 Parent(s): f4d5990
Files changed (1) hide show
  1. app.py +11 -32
app.py CHANGED
@@ -1,33 +1,12 @@
1
- import requests
2
-
3
  import gradio as gr
4
- import torch
5
- from timm import create_model
6
- from timm.data import resolve_data_config
7
- from timm.data.tranforms import create_transform
8
-
9
- from transformers import AutoFeatureExtractor, AutoModelForImageClassification
10
-
11
-
12
- extractor = AutoFeatureExtractor.from_pretrained("abhishek/autotrain_fashion_mnist_vit_base")
13
- model = AutoModelForImageClassification.from_pretrained("abhishek/autotrain_fashion_mnist_vit_base")
14
- transform = create_transform(
15
- **resolve_data_config({}, model=model)
16
- )
17
-
18
- model.eval()
19
-
20
- def predict_fn(img):
21
- img = img.convert('RGB')
22
- img = transform(img).unsqueeze(0)
23
-
24
- with torch.no_grad():
25
- out = model(img)
26
-
27
- probabilites = torch.nn.functional.softmax(out[0], dim=0)
28
-
29
- values, indices = torch.topk(probabilites, k=5)
30
-
31
- return {LABELS[i]: v.item() for i, v in zip(indices, values)}
32
-
33
- gr.Interface(predict_fn, gr.inputs.Image(type='pil'), outputs='label').launch()
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ pipe = pipeline(task="image-classification",
5
+ # model that can do 22k-category classification
6
+ model="abhishek/autotrain_fashion_mnist_vit_base")
7
+ gr.Interface.from_pipeline(pipe,
8
+ title="22k Image Classification",
9
+ description="Object Recognition using Microsoft BEIT",
10
+ examples = ['wonder_cat.jpg', 'aki_dog.jpg',],
11
+ article = "Author: <a href=\"https://huggingface.co/rowel\">Rowel Atienza</a>",
12
+ ).launch()