Spaces:
Runtime error
Runtime error
# import requests | |
# res = requests.get("https://seyarabata.com/6370e77fec965") | |
# with open("last.ckpt", 'wb') as f: | |
# f.write(res.content) | |
import os | |
os.system('curl "https://seyarabata.com/6370e77fec965" -L -O last.ckpt') | |
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() | |
from strhub.models.parseq.system import PARSeq as ModelClass | |
parseq = ModelClass.load_from_checkpoint("last.ckpt").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() |