Aalaa commited on
Commit
c3394c8
1 Parent(s): 615951e
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import (
2
+ TrOCRConfig,
3
+ TrOCRProcessor,
4
+ TrOCRForCausalLM,
5
+ ViTConfig,
6
+ ViTModel,
7
+ VisionEncoderDecoderModel,
8
+ )
9
+ import gradio as gr
10
+
11
+ processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
12
+ model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")
13
+ def ocr(image):
14
+ pixel_values = processor(image, return_tensors="pt").pixel_values
15
+ generated_ids = model.generate(pixel_values)
16
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
17
+ return generated_text
18
+
19
+
20
+ demo = gr.Interface(fn=ocr, inputs="image",outputs= ["text"])
21
+ demo.launch()