muddokon commited on
Commit
3f7f130
·
verified ·
1 Parent(s): ecbe19c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -4
app.py CHANGED
@@ -1,7 +1,33 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import VisionEncoderDecoderModel, TrOCRProcessor
3
+ import torch
4
 
5
+ def recognize_captcha(input, mdl):
6
+ input = transform(input.convert('RGB'))
7
 
8
+ # Load model and processor
9
+ processor = TrOCRProcessor.from_pretrained(mdl)
10
+ model = VisionEncoderDecoderModel.from_pretrained(mdl)
11
+
12
+ # Prepare image
13
+ pixel_values = processor(input, return_tensors="pt").pixel_values
14
+
15
+ # Generate text
16
+ generated_ids = model.generate(pixel_values)
17
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
18
+ return generated_text
19
+
20
+ iface = gr.Interface(
21
+ recognize_captcha[
22
+ gr.Image,
23
+ gr.Dropdown(
24
+ ['anuashok/ocr-captcha-v3','anuashok/ocr-captcha-v2','anuashok/ocr-captcha-v1'], label='Model to use'
25
+ )
26
+ ],
27
+ 'text',
28
+ title = "character sequence recognition from scene-image (captcha)",
29
+ description = "Using some TrOCR models found on the HF Hub. Will you have to train your own?",
30
+ examples = ['','']
31
+ )
32
+
33
+ iface.launch()