Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,3 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
import tensorflow as tf
|
5 |
from matplotlib import pyplot as plt
|
6 |
from skimage.transform import rescale, resize
|
@@ -14,57 +11,37 @@ import gradio as gr
|
|
14 |
import data
|
15 |
|
16 |
|
17 |
-
#### training setup parameters ####
|
18 |
-
|
19 |
-
|
20 |
-
lambda_val=1e-4
|
21 |
-
gamma_val=1
|
22 |
|
23 |
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
|
24 |
|
25 |
|
26 |
|
27 |
-
################################### Utility functions###################################
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
# Create an instance of the model
|
32 |
CALTEXT = CALTextModel.CALTEXT_Model(training=False)
|
33 |
CALTEXT.load_weights('final_caltextModel/cp-0037.ckpt')
|
34 |
test_loss = tf.keras.metrics.Mean(name='test_loss')
|
35 |
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
examples = [
|
41 |
-
['sample_test_images/59-11.png'],
|
42 |
-
['sample_test_images/59-21.png'],
|
43 |
-
['sample_test_images/59-32.png'],
|
44 |
-
['sample_test_images/59-37.png'],
|
45 |
-
['sample_test_images/91-47.png'],
|
46 |
-
['sample_test_images/91-49.png'],
|
47 |
-
]
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
def recognize_text(input_image):
|
53 |
x, x_mask=data.preprocess_img(input_image)
|
54 |
output_str, gifImage=CALTextModel.predict(x, x_mask)
|
55 |
return output_str,gifImage
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
title = "CALText Demo"
|
59 |
description = "<p style='text-align: center'>Gradio demo for an CALText model architecture <a href='https://github.com/nazar-khan/CALText'>[GitHub Code]</a> trained on the <a href='http://faculty.pucit.edu.pk/nazarkhan/work/urdu_ohtr/pucit_ohul_dataset.html'>PUCIT-OHUL</a> dataset. To use it, simply add your image, or click one of the examples to load them. </p>"
|
60 |
article = "<p style='text-align: center'></p>"
|
61 |
-
css = "#0 {object-fit: contain;} #1 {object-fit: contain;}"
|
62 |
inputs = gr.inputs.Image(label="Input Image")
|
63 |
|
64 |
demo = gr.Interface(fn=recognize_text,
|
65 |
inputs=inputs,
|
66 |
-
outputs=[gr.Textbox(label="Output"),
|
67 |
-
gr.Image(label="Attended Regions")],
|
68 |
examples=examples,
|
69 |
title=title,
|
70 |
description=description,
|
|
|
|
|
|
|
|
|
1 |
import tensorflow as tf
|
2 |
from matplotlib import pyplot as plt
|
3 |
from skimage.transform import rescale, resize
|
|
|
11 |
import data
|
12 |
|
13 |
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
|
16 |
|
17 |
|
18 |
|
|
|
|
|
|
|
|
|
19 |
# Create an instance of the model
|
20 |
CALTEXT = CALTextModel.CALTEXT_Model(training=False)
|
21 |
CALTEXT.load_weights('final_caltextModel/cp-0037.ckpt')
|
22 |
test_loss = tf.keras.metrics.Mean(name='test_loss')
|
23 |
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
def recognize_text(input_image):
|
26 |
x, x_mask=data.preprocess_img(input_image)
|
27 |
output_str, gifImage=CALTextModel.predict(x, x_mask)
|
28 |
return output_str,gifImage
|
29 |
|
30 |
+
examples = [['sample_test_images/59-11.png'],
|
31 |
+
['sample_test_images/59-21.png'],
|
32 |
+
['sample_test_images/59-32.png'],
|
33 |
+
['sample_test_images/59-37.png'],
|
34 |
+
['sample_test_images/91-47.png'],
|
35 |
+
['sample_test_images/91-49.png']]
|
36 |
|
37 |
title = "CALText Demo"
|
38 |
description = "<p style='text-align: center'>Gradio demo for an CALText model architecture <a href='https://github.com/nazar-khan/CALText'>[GitHub Code]</a> trained on the <a href='http://faculty.pucit.edu.pk/nazarkhan/work/urdu_ohtr/pucit_ohul_dataset.html'>PUCIT-OHUL</a> dataset. To use it, simply add your image, or click one of the examples to load them. </p>"
|
39 |
article = "<p style='text-align: center'></p>"
|
|
|
40 |
inputs = gr.inputs.Image(label="Input Image")
|
41 |
|
42 |
demo = gr.Interface(fn=recognize_text,
|
43 |
inputs=inputs,
|
44 |
+
outputs=[gr.Textbox(label="Output"), gr.Image(label="Attended Regions")],
|
|
|
45 |
examples=examples,
|
46 |
title=title,
|
47 |
description=description,
|