Spaces:
Build error
Build error
from transformers import ViTFeatureExtractor, BertTokenizer, VisionEncoderDecoderModel, AutoTokenizer | |
import gradio as gr | |
model=VisionEncoderDecoderModel.from_pretrained("priyank-m/vit-bert-OCR") | |
tokenizer = AutoTokenizer.from_pretrained("bert-base-multilingual-cased") | |
feature_extractor = ViTFeatureExtractor.from_pretrained("google/vit-large-patch32-384") | |
def run_ocr(image): | |
pixel_values = feature_extractor(image, return_tensors="pt").pixel_values | |
# autoregressively generate caption (uses greedy decoding by default ) | |
generated_ids = model.generate(pixel_values, max_new_tokens=50) | |
generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0] | |
return generated_text | |
demo = gr.Interface(fn=run_ocr, inputs="image", outputs="text") | |
demo.launch() |