Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ TOKEN = os.getenv('hf_read_token')
|
|
| 9 |
repo_id = "Nischay103/captcha_recognition"
|
| 10 |
model_file = 'captcha_model.pt'
|
| 11 |
model_path = hf_hub_download(repo_id=repo_id, filename=model_file, token=TOKEN)
|
| 12 |
-
model = torch.jit.load(model_path)
|
| 13 |
|
| 14 |
charset = r"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| 15 |
_tokenizer = Tokenizer(charset)
|
|
@@ -24,14 +24,14 @@ def get_transform(img_size=(32,128)):
|
|
| 24 |
return T.Compose(transforms)
|
| 25 |
|
| 26 |
transform = get_transform()
|
| 27 |
-
image = gr.Image(type="filepath", label="
|
| 28 |
-
text = gr.Textbox(label="
|
| 29 |
|
| 30 |
|
| 31 |
def recognize_captcha(image_path):
|
| 32 |
input = Image.open(image_path)
|
| 33 |
input = transform(input.convert('RGB')).unsqueeze(0)
|
| 34 |
-
model =
|
| 35 |
with torch.no_grad():
|
| 36 |
probs = model(input)
|
| 37 |
preds,_ = _tokenizer.decode(probs,beam_width=2)
|
|
@@ -41,8 +41,8 @@ iface = gr.Interface(
|
|
| 41 |
fn=recognize_captcha,
|
| 42 |
inputs=image,
|
| 43 |
outputs=text,
|
| 44 |
-
title="
|
| 45 |
-
description="
|
| 46 |
examples=['examples/251615.png']
|
| 47 |
)
|
| 48 |
|
|
|
|
| 9 |
repo_id = "Nischay103/captcha_recognition"
|
| 10 |
model_file = 'captcha_model.pt'
|
| 11 |
model_path = hf_hub_download(repo_id=repo_id, filename=model_file, token=TOKEN)
|
| 12 |
+
# model = torch.jit.load(model_path)
|
| 13 |
|
| 14 |
charset = r"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| 15 |
_tokenizer = Tokenizer(charset)
|
|
|
|
| 24 |
return T.Compose(transforms)
|
| 25 |
|
| 26 |
transform = get_transform()
|
| 27 |
+
image = gr.Image(type="filepath", label="captcha image")
|
| 28 |
+
text = gr.Textbox(label="recognized character sequence")
|
| 29 |
|
| 30 |
|
| 31 |
def recognize_captcha(image_path):
|
| 32 |
input = Image.open(image_path)
|
| 33 |
input = transform(input.convert('RGB')).unsqueeze(0)
|
| 34 |
+
model = torch.jit.load(model_path)
|
| 35 |
with torch.no_grad():
|
| 36 |
probs = model(input)
|
| 37 |
preds,_ = _tokenizer.decode(probs,beam_width=2)
|
|
|
|
| 41 |
fn=recognize_captcha,
|
| 42 |
inputs=image,
|
| 43 |
outputs=text,
|
| 44 |
+
title="character sequence recognition from scene-image (captcha)",
|
| 45 |
+
description="recognize captchas ",
|
| 46 |
examples=['examples/251615.png']
|
| 47 |
)
|
| 48 |
|