Spaces:
Runtime error
Runtime error
test
Browse files
app.py
CHANGED
@@ -21,15 +21,15 @@ import torch
|
|
21 |
from mmocr.apis import MMOCRInferencer
|
22 |
ocr = MMOCRInferencer(det='TextSnake', rec='ABINet_Vision')
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
|
34 |
# model = keras_model(weights="imagenet")
|
35 |
|
@@ -41,7 +41,8 @@ ocr = MMOCRInferencer(det='TextSnake', rec='ABINet_Vision')
|
|
41 |
# )
|
42 |
|
43 |
|
44 |
-
|
|
|
45 |
# instance = image.img_to_array(img)
|
46 |
# instance = np.expand_dims(instance, axis=0)
|
47 |
# instance = preprocess_input(instance)
|
@@ -85,9 +86,9 @@ ocr = MMOCRInferencer(det='TextSnake', rec='ABINet_Vision')
|
|
85 |
# return img_res, img_flt, dctPreds
|
86 |
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
# input_drop = gr.inputs.Dropdown(
|
92 |
# label="Baseline (default: random)",
|
93 |
# choices=["random", "black", "white", "blur"],
|
@@ -95,24 +96,24 @@ ocr = MMOCRInferencer(det='TextSnake', rec='ABINet_Vision')
|
|
95 |
# type="value",
|
96 |
# )
|
97 |
|
98 |
-
|
99 |
# output_base = gr.outputs.Image(label="Baseline image", type="pil")
|
100 |
# output_label = gr.outputs.Label(label="Classification results", num_top_classes=3)
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
|
118 |
# iface.launch(debug=True)
|
|
|
21 |
from mmocr.apis import MMOCRInferencer
|
22 |
ocr = MMOCRInferencer(det='TextSnake', rec='ABINet_Vision')
|
23 |
|
24 |
+
url = (
|
25 |
+
"https://upload.wikimedia.org/wikipedia/commons/3/38/Adorable-animal-cat-20787.jpg"
|
26 |
+
)
|
27 |
+
path_input = "./cat.jpg"
|
28 |
+
urllib.request.urlretrieve(url, filename=path_input)
|
29 |
|
30 |
+
url = "https://upload.wikimedia.org/wikipedia/commons/4/43/Cute_dog.jpg"
|
31 |
+
path_input = "./dog.jpg"
|
32 |
+
urllib.request.urlretrieve(url, filename=path_input)
|
33 |
|
34 |
# model = keras_model(weights="imagenet")
|
35 |
|
|
|
41 |
# )
|
42 |
|
43 |
|
44 |
+
def do_process(img, baseline):
|
45 |
+
return img
|
46 |
# instance = image.img_to_array(img)
|
47 |
# instance = np.expand_dims(instance, axis=0)
|
48 |
# instance = preprocess_input(instance)
|
|
|
86 |
# return img_res, img_flt, dctPreds
|
87 |
|
88 |
|
89 |
+
input_im = gr.inputs.Image(
|
90 |
+
shape=(224, 224), image_mode="RGB", invert_colors=False, source="upload", type="pil"
|
91 |
+
)
|
92 |
# input_drop = gr.inputs.Dropdown(
|
93 |
# label="Baseline (default: random)",
|
94 |
# choices=["random", "black", "white", "blur"],
|
|
|
96 |
# type="value",
|
97 |
# )
|
98 |
|
99 |
+
output_img = gr.outputs.Image(label="Output of Integrated Gradients", type="pil")
|
100 |
# output_base = gr.outputs.Image(label="Baseline image", type="pil")
|
101 |
# output_label = gr.outputs.Label(label="Classification results", num_top_classes=3)
|
102 |
|
103 |
+
title = "XAI - Integrated gradients"
|
104 |
+
description = "Playground: Integrated gradients for a ResNet model trained on Imagenet dataset. Tools: Alibi, TF, Gradio."
|
105 |
+
examples = [["./cat.jpg", "blur"], ["./dog.jpg", "random"]]
|
106 |
+
article = "<p style='text-align: center'><a href='https://github.com/mawady' target='_blank'>By Dr. Mohamed Elawady</a></p>"
|
107 |
+
iface = gr.Interface(
|
108 |
+
fn=do_process,
|
109 |
+
inputs=[input_im],
|
110 |
+
outputs=[output_img],
|
111 |
+
live=False,
|
112 |
+
interpretation=None,
|
113 |
+
title=title,
|
114 |
+
description=description,
|
115 |
+
article=article,
|
116 |
+
examples=examples,
|
117 |
+
)
|
118 |
|
119 |
# iface.launch(debug=True)
|