Spaces:
Runtime error
Runtime error
Commit ·
87706f0
1
Parent(s): 4c396dc
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,12 @@ os.system("unzip blobzip.zip");
|
|
| 8 |
|
| 9 |
import torch, pickle, strhub
|
| 10 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# from strhub.data.module import SceneTextDataModule
|
| 12 |
# from strhub.models.utils import load_from_checkpoint, parse_model_args
|
| 13 |
|
|
@@ -39,21 +45,37 @@ parseq = torch.load('tensor.pt', map_location=torch.device('cpu')).eval()
|
|
| 39 |
|
| 40 |
img_transform = get_transform(parseq.hparams.img_size, augment=True)
|
| 41 |
|
| 42 |
-
img = Image.open('oscqt.jpeg').convert('RGB')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
logits.shape
|
| 47 |
|
| 48 |
-
#
|
| 49 |
-
|
| 50 |
-
label, confidence = parseq.tokenizer.decode(pred)
|
| 51 |
-
print('Decoded label = {}'.format(label[0]))
|
| 52 |
|
| 53 |
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
|
|
|
| 8 |
|
| 9 |
import torch, pickle, strhub
|
| 10 |
from PIL import Image
|
| 11 |
+
print(f"Is CUDA available: {torch.cuda.is_available()}")
|
| 12 |
+
|
| 13 |
+
# True
|
| 14 |
+
print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
# from strhub.data.module import SceneTextDataModule
|
| 18 |
# from strhub.models.utils import load_from_checkpoint, parse_model_args
|
| 19 |
|
|
|
|
| 45 |
|
| 46 |
img_transform = get_transform(parseq.hparams.img_size, augment=True)
|
| 47 |
|
| 48 |
+
# img = Image.open('oscqt.jpeg').convert('RGB')
|
| 49 |
+
|
| 50 |
+
# img = img_transform(img).unsqueeze(0)
|
| 51 |
+
# logits = parseq(img)
|
| 52 |
+
# logits.shape
|
| 53 |
+
|
| 54 |
+
# # # Greedy decoding
|
| 55 |
+
# pred = logits.softmax(-1)
|
| 56 |
+
# label, confidence = parseq.tokenizer.decode(pred)
|
| 57 |
+
# print('Decoded label = {}'.format(label[0]))
|
| 58 |
+
|
| 59 |
+
|
| 60 |
|
| 61 |
+
# def greet(name):
|
| 62 |
+
# return "Hello " + name + "!!"
|
|
|
|
| 63 |
|
| 64 |
+
# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 65 |
+
# iface.launch()
|
|
|
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
+
def captcha_solver(img):
|
| 69 |
+
img = img.convert('RGB')
|
| 70 |
+
img = img_transform(img).unsqueeze(0)
|
| 71 |
|
| 72 |
+
logits = parseq(img)
|
| 73 |
+
logits.shape
|
| 74 |
+
|
| 75 |
+
# # Greedy decoding
|
| 76 |
+
pred = logits.softmax(-1)
|
| 77 |
+
label, confidence = parseq.tokenizer.decode(pred)
|
| 78 |
+
return label[0]
|
| 79 |
|
| 80 |
+
demo = gr.Interface(fn=captcha_solver, inputs=gr.inputs.Image(type="pil"), outputs=gr.outputs.Textbox())
|
| 81 |
+
demo.launch()
|