sdfswefrwerwe commited on
Commit
3a98e6b
1 Parent(s): f0fa8ce
Files changed (1) hide show
  1. app.py +46 -4
app.py CHANGED
@@ -1,7 +1,49 @@
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import TrOCRProcessor, VisionEncoderDecoderModel
3
+ import requests
4
+ from PIL import Image
5
 
6
+ processor = TrOCRProcessor.from_pretrained("microsoft/trocr-small-printed")
7
+ model = VisionEncoderDecoderModel.from_pretrained("pENrknSoysneed/8kun-captcha-ocr-meme")
8
 
9
+ # load image examples
10
+ urls = [
11
+ 'https://storage.googleapis.com/trocr-captcha.appspot.com/captcha_images_v2/nfcb5.png',
12
+ 'https://storage.googleapis.com/trocr-captcha.appspot.com/captcha_images_v2/p57fn.png',
13
+ 'https://storage.googleapis.com/trocr-captcha.appspot.com/captcha_images_v2/w2yp7.png',
14
+ 'https://storage.googleapis.com/trocr-captcha.appspot.com/captcha_images_v2/pme86.png',
15
+ 'https://storage.googleapis.com/trocr-captcha.appspot.com/captcha_images_v2/w4nfx.png',
16
+ 'https://storage.googleapis.com/trocr-captcha.appspot.com/captcha_images_v2/nf8b8.png'
17
+ ]
18
+ for idx, url in enumerate(urls):
19
+ image = Image.open(requests.get(url, stream=True).raw)
20
+ image.save(f"image_{idx}.png")
21
+
22
+ def process_image(image):
23
+ # prepare image
24
+ pixel_values = processor(image, return_tensors="pt").pixel_values
25
+
26
+ # generate (no beam search)
27
+ generated_ids = model.generate(pixel_values)
28
+
29
+ # decode
30
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
31
+
32
+ return generated_text
33
+
34
+ title = "Who is that? Its a racoon ??? 2022 20021 and the year is 5400bc"
35
+ description = "What the???? a weird graygreen racconn on my board REEEEEEEEEEEEEEEEEEEEEEEE PEEEPEEE PEPEPEEE REEEE."
36
+ # article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2109.10282'>TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models</a> | <a href='https://github.com/microsoft/unilm/tree/master/trocr'>Github Repo</a></p>"
37
+ # examples =[["image_0.png"], ["image_1.png"], ["image_2.png"], ["image_3.png"], ["image_4.png"], ["image_5.png"]]
38
+
39
+ #css = """.output_image, .input_image {height: 600px !important}"""
40
+
41
+ iface = gr.Interface(fn=process_image,
42
+ inputs=gr.inputs.Image(type="pil"),
43
+ outputs=gr.outputs.Textbox(),
44
+ title=title,
45
+ description=description,
46
+ # article=article,
47
+ # examples=examples
48
+ )
49
+ iface.launch(debug=True)