deeksonparlma
commited on
Commit
·
7523d7d
1
Parent(s):
dbb1504
- AppleCedarRust3.jpg +0 -0
- TomatoHealthy2.jpg +0 -0
- TomatoYellowCurlVirus3.jpg +0 -0
- app.py +76 -0
- requirements.txt +99 -0
AppleCedarRust3.jpg
ADDED
TomatoHealthy2.jpg
ADDED
TomatoYellowCurlVirus3.jpg
ADDED
app.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# %%
|
2 |
+
import gradio as gr
|
3 |
+
import tensorflow as tf
|
4 |
+
import cv2
|
5 |
+
import os
|
6 |
+
|
7 |
+
model_folder = 'model'
|
8 |
+
destination = model_folder
|
9 |
+
repo_url = "https://huggingface.co/RandomCatLover/plants_disease"
|
10 |
+
|
11 |
+
if not os.path.exists(destination):
|
12 |
+
import subprocess
|
13 |
+
#repo_url = os.getenv("GIT_CORE")
|
14 |
+
command = f'git clone {repo_url} {destination}'
|
15 |
+
try:
|
16 |
+
subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)#, env=env)
|
17 |
+
print('Repository cloned successfully.')
|
18 |
+
except subprocess.CalledProcessError as e:
|
19 |
+
print(f'Error cloning repository: {e.output.decode()}')
|
20 |
+
|
21 |
+
destination = 'explainer_tf_mobilenetv2'
|
22 |
+
if not os.path.exists(destination):
|
23 |
+
import subprocess
|
24 |
+
repo_url = os.getenv("GIT_CORE")
|
25 |
+
command = f'git clone {repo_url}'
|
26 |
+
try:
|
27 |
+
subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)#, env=env)
|
28 |
+
print('Repository cloned successfully.')
|
29 |
+
except subprocess.CalledProcessError as e:
|
30 |
+
print(f'Error cloning repository: {e.output.decode()}')
|
31 |
+
|
32 |
+
from explainer_tf_mobilenetv2.explainer import explainer
|
33 |
+
# %%
|
34 |
+
with open(f'{model_folder}/labels.txt', 'r') as f:
|
35 |
+
labels = f.read().split('\n')
|
36 |
+
|
37 |
+
# model = tf.saved_model.load(f'{model_folder}/last_layer.hdf5')
|
38 |
+
model = tf.keras.models.load_model(f'{model_folder}/last_layer.hdf5')
|
39 |
+
#model = tf.keras.models.load_model(f'{model_folder}/MobileNetV2_last_layer.hdf5')
|
40 |
+
# %%
|
41 |
+
def classify_image(inp):
|
42 |
+
inp = cv2.resize(inp, (224,224,))
|
43 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
44 |
+
inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
|
45 |
+
prediction = model.predict(inp).flatten()
|
46 |
+
print(prediction)
|
47 |
+
confidences = {labels[i]: float(prediction[i]) for i in range(len(labels))}
|
48 |
+
return confidences
|
49 |
+
|
50 |
+
def explainer_wrapper(inp):
|
51 |
+
return explainer(inp, model)
|
52 |
+
|
53 |
+
with gr.Blocks() as demo:
|
54 |
+
with gr.Column():
|
55 |
+
with gr.Row():
|
56 |
+
with gr.Column():
|
57 |
+
image = gr.inputs.Image(shape=(224, 224))
|
58 |
+
with gr.Row():
|
59 |
+
classify = gr.Button("Classify")
|
60 |
+
interpret = gr.Button("Interpret")
|
61 |
+
with gr.Column():
|
62 |
+
label = gr.outputs.Label(num_top_classes=3)
|
63 |
+
interpretation = gr.Plot(label="Interpretation")
|
64 |
+
# interpretation = gr.outputs.Image(type="numpy", label="Interpretation")
|
65 |
+
gr.Examples(["TomatoHealthy2.jpg", "TomatoYellowCurlVirus3.jpg", "AppleCedarRust3.jpg"],
|
66 |
+
inputs=[image],)
|
67 |
+
classify.click(classify_image, image, label, queue=True)
|
68 |
+
interpret.click(explainer_wrapper, image, interpretation, queue=True)
|
69 |
+
|
70 |
+
|
71 |
+
demo.queue(concurrency_count=3).launch()
|
72 |
+
#%%
|
73 |
+
# gr.Interface(fn=classify_image,
|
74 |
+
# inputs=gr.Image(shape=(224, 224)),
|
75 |
+
# outputs=gr.Label(num_top_classes=3),
|
76 |
+
# examples=["TomatoHealthy2.jpg", "TomatoYellowCurlVirus3.jpg", "AppleCedarRust3.jpg"]).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
absl-py==1.4.0
|
2 |
+
aiofiles==23.1.0
|
3 |
+
aiohttp==3.8.4
|
4 |
+
aiosignal==1.3.1
|
5 |
+
altair==5.0.0
|
6 |
+
anyio==3.6.2
|
7 |
+
astunparse==1.6.3
|
8 |
+
async-timeout==4.0.2
|
9 |
+
attrs==23.1.0
|
10 |
+
cachetools==5.3.0
|
11 |
+
certifi==2023.5.7
|
12 |
+
charset-normalizer==3.1.0
|
13 |
+
click==8.1.3
|
14 |
+
contourpy==1.0.7
|
15 |
+
cycler==0.11.0
|
16 |
+
fastapi==0.95.2
|
17 |
+
ffmpy==0.3.0
|
18 |
+
filelock==3.12.0
|
19 |
+
flatbuffers==23.5.9
|
20 |
+
fonttools==4.39.4
|
21 |
+
frozenlist==1.3.3
|
22 |
+
fsspec==2023.5.0
|
23 |
+
gast==0.4.0
|
24 |
+
google-auth==2.18.1
|
25 |
+
google-auth-oauthlib==1.0.0
|
26 |
+
google-pasta==0.2.0
|
27 |
+
gradio==3.31.0
|
28 |
+
gradio_client==0.2.5
|
29 |
+
grpcio==1.54.2
|
30 |
+
h11==0.14.0
|
31 |
+
h5py==3.8.0
|
32 |
+
httpcore==0.17.1
|
33 |
+
httpx==0.24.1
|
34 |
+
huggingface-hub==0.14.1
|
35 |
+
idna==3.4
|
36 |
+
importlib-metadata==6.6.0
|
37 |
+
importlib-resources==5.12.0
|
38 |
+
jax==0.4.10
|
39 |
+
Jinja2==3.1.2
|
40 |
+
jsonschema==4.17.3
|
41 |
+
keras==2.12.0
|
42 |
+
kiwisolver==1.4.4
|
43 |
+
libclang==16.0.0
|
44 |
+
linkify-it-py==2.0.2
|
45 |
+
Markdown==3.4.3
|
46 |
+
markdown-it-py==2.2.0
|
47 |
+
MarkupSafe==2.1.2
|
48 |
+
matplotlib==3.7.1
|
49 |
+
mdit-py-plugins==0.3.3
|
50 |
+
mdurl==0.1.2
|
51 |
+
ml-dtypes==0.1.0
|
52 |
+
multidict==6.0.4
|
53 |
+
numpy==1.23.5
|
54 |
+
oauthlib==3.2.2
|
55 |
+
opencv-python==4.7.0.72
|
56 |
+
opt-einsum==3.3.0
|
57 |
+
orjson==3.8.12
|
58 |
+
packaging==23.1
|
59 |
+
pandas==2.0.1
|
60 |
+
Pillow==9.5.0
|
61 |
+
pkgutil_resolve_name==1.3.10
|
62 |
+
protobuf==4.23.1
|
63 |
+
pyasn1==0.5.0
|
64 |
+
pyasn1-modules==0.3.0
|
65 |
+
pydantic==1.10.7
|
66 |
+
pydub==0.25.1
|
67 |
+
Pygments==2.15.1
|
68 |
+
pyparsing==3.0.9
|
69 |
+
pyrsistent==0.19.3
|
70 |
+
python-dateutil==2.8.2
|
71 |
+
python-multipart==0.0.6
|
72 |
+
pytz==2023.3
|
73 |
+
PyYAML==6.0
|
74 |
+
requests==2.30.0
|
75 |
+
requests-oauthlib==1.3.1
|
76 |
+
rsa==4.9
|
77 |
+
scipy==1.10.1
|
78 |
+
semantic-version==2.10.0
|
79 |
+
six==1.16.0
|
80 |
+
sniffio==1.3.0
|
81 |
+
starlette==0.27.0
|
82 |
+
tensorboard==2.12.3
|
83 |
+
tensorboard-data-server==0.7.0
|
84 |
+
tensorflow==2.12.0
|
85 |
+
tensorflow-estimator==2.12.0
|
86 |
+
tensorflow-io-gcs-filesystem==0.32.0
|
87 |
+
termcolor==2.3.0
|
88 |
+
toolz==0.12.0
|
89 |
+
tqdm==4.65.0
|
90 |
+
typing_extensions==4.5.0
|
91 |
+
tzdata==2023.3
|
92 |
+
uc-micro-py==1.0.2
|
93 |
+
urllib3==1.26.15
|
94 |
+
uvicorn==0.22.0
|
95 |
+
websockets==11.0.3
|
96 |
+
Werkzeug==2.3.4
|
97 |
+
wrapt==1.14.1
|
98 |
+
yarl==1.9.2
|
99 |
+
zipp==3.15.0
|