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