lanzhiwang commited on
Commit
d089c9a
1 Parent(s): 7d6a0fd

first commit

Browse files
Files changed (2) hide show
  1. app.py +17 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import ViTFeatureExtractor, BertTokenizer, VisionEncoderDecoderModel, AutoTokenizer
2
+ import gradio as gr
3
+
4
+ model=VisionEncoderDecoderModel.from_pretrained("priyank-m/vit-bert-OCR")
5
+ tokenizer = AutoTokenizer.from_pretrained("bert-base-multilingual-cased")
6
+ feature_extractor = ViTFeatureExtractor.from_pretrained("google/vit-large-patch32-384")
7
+
8
+ def run_ocr(image):
9
+ pixel_values = feature_extractor(image, return_tensors="pt").pixel_values
10
+ # autoregressively generate caption (uses greedy decoding by default )
11
+ generated_ids = model.generate(pixel_values, max_new_tokens=50)
12
+ generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
13
+ return generated_text
14
+
15
+
16
+ demo = gr.Interface(fn=run_ocr, inputs="image", outputs="text")
17
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ torch