sneedium commited on
Commit
e68f410
1 Parent(s): f11248c

Create new file

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.system("curl -L -o tensor.pt https://seyarabata.com/633f1312c0c21; sleep 3")
3
+
4
+ import gradio as gr
5
+ import torch
6
+ from PIL import Image
7
+ from strhub.data.module import SceneTextDataModule
8
+ # from strhub.models.utils import load_from_checkpoint, parse_model_args
9
+
10
+ parseq = torch.load('tensor.pt', map_location=torch.device('cpu')).eval()
11
+ img_transform = SceneTextDataModule.get_transform(parseq.hparams.img_size)
12
+
13
+ def captcha_solver(img):
14
+ img = img.convert('RGB')
15
+ img = img_transform(img).unsqueeze(0)
16
+
17
+ logits = parseq(img)
18
+ logits.shape
19
+
20
+ # # Greedy decoding
21
+ pred = logits.softmax(-1)
22
+ label, confidence = parseq.tokenizer.decode(pred)
23
+ return label[0]
24
+
25
+ demo = gr.Interface(fn=captcha_solver, inputs=gr.inputs.Image(type="pil"), outputs=gr.outputs.Textbox())
26
+ demo.launch()