Wootang01 commited on
Commit
b28f796
·
1 Parent(s): 3d7e8cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -30
app.py CHANGED
@@ -1,31 +1,16 @@
1
  import gradio as gr
2
- import torch
3
-
4
- from timm import create_model
5
- from timm.data import resolve_data_config
6
- from timm.data.transforms_factory import create_transform
7
-
8
- IMAGENET_1k_URL = "https://storage.googleapis.com/bit_models/ilsvrc2012_wordnet_lemmas.txt"
9
- LABELS = requests.get(IMAGENET_1k_URL).text.strip().split('\n')
10
-
11
- model = create_model('resnet50', pretrained=True)
12
-
13
- transform = create_transform(
14
- **resolve_data_config({}, model=model)
15
- )
16
- model.eval()
17
-
18
- def predict_fn(img):
19
- img = img.convert('RGB')
20
- img = transform(img).unsqueeze(0)
21
-
22
- with torch.no_grad():
23
- out = model(img)
24
-
25
- probabilites = torch.nn.functional.softmax(out[0], dim=0)
26
-
27
- values, indices = torch.topk(probabilites, k=5)
28
-
29
- return {LABELS[i]: v.item() for i, v in zip(indices, values)}
30
-
31
- gr.Interface(predict_fn, gr.inputs.Image(type='pil'), outputs='label').launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ title = "Document Image Transformer"
5
+ description = "Gradio Demo for DiT, the Document Image Transformer pre-trained on IIT-CDIP, a dataset that includes 42 million document images and fine-tuned on RVL-CDIP, a dataset consisting of 400,000 grayscale images in 16 classes, with 25,000 images per class. To use it, simply add your image, or click one of the examples to load them. Read more at the links below."
6
+ article = "<p style='text-align: center'><a href='https://huggingface.co/microsoft/dit-base-finetuned-rvlcdip' target='_blank'>Huggingface Model</a></p>"
7
+
8
+ pipe = pipeline(task="image-classification",
9
+ model="microsoft/dit-base-finetuned-rvlcdip")
10
+ gr.Interface.from_pipeline(pipe,
11
+ title=title,
12
+ description=description,
13
+ examples=['coca_cola_advertisement.png', 'scientific_publication.png', 'letter.jpeg'],
14
+ article=article,
15
+ enable_queue=True,
16
+ ).launch()