Spaces:
Sleeping
Sleeping
Matej
commited on
Commit
·
ad7849a
1
Parent(s):
eeaa8d0
fix dependency error
Browse files- my_app.py +6 -15
- requirements.txt +3 -97
my_app.py
CHANGED
@@ -1,12 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
-
import numpy as np
|
4 |
-
from PIL import Image
|
5 |
from huggingface_hub import from_pretrained_keras
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
# Load your trained models
|
11 |
model1 = from_pretrained_keras("ml-debi/EfficientNetB0-Food101")
|
12 |
model2 = from_pretrained_keras("ml-debi/EfficientNetB0-Food101")
|
@@ -27,23 +22,19 @@ model2_info = """
|
|
27 |
This model is based on the EfficientNetB0 architecture and was trained on augmented data, providing improved generalization.
|
28 |
"""
|
29 |
|
30 |
-
def preprocess(image
|
31 |
-
|
32 |
-
image =
|
33 |
-
image = image.resize((224, 224)) # replace with the input size of your models
|
34 |
-
image = np.array(image)
|
35 |
-
# image = image / 255.0 # normalize if you've done so while training
|
36 |
-
image = np.expand_dims(image, axis=0)
|
37 |
return image
|
38 |
|
39 |
-
def predict(model_selection, image
|
40 |
# Choose the model based on the dropdown selection
|
41 |
model = model1 if model_selection == "EfficentNetB0 Fine Tune" else model2
|
42 |
|
43 |
image = preprocess(image)
|
44 |
prediction = model.predict(image)
|
45 |
-
predicted_class = classes[
|
46 |
-
confidence =
|
47 |
return predicted_class, confidence
|
48 |
|
49 |
iface = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
|
|
|
|
3 |
from huggingface_hub import from_pretrained_keras
|
4 |
|
|
|
|
|
|
|
5 |
# Load your trained models
|
6 |
model1 = from_pretrained_keras("ml-debi/EfficientNetB0-Food101")
|
7 |
model2 = from_pretrained_keras("ml-debi/EfficientNetB0-Food101")
|
|
|
22 |
This model is based on the EfficientNetB0 architecture and was trained on augmented data, providing improved generalization.
|
23 |
"""
|
24 |
|
25 |
+
def preprocess(image):
|
26 |
+
image = tf.image.resize(image, [224, 224])
|
27 |
+
image = tf.expand_dims(image, axis=0)
|
|
|
|
|
|
|
|
|
28 |
return image
|
29 |
|
30 |
+
def predict(model_selection, image):
|
31 |
# Choose the model based on the dropdown selection
|
32 |
model = model1 if model_selection == "EfficentNetB0 Fine Tune" else model2
|
33 |
|
34 |
image = preprocess(image)
|
35 |
prediction = model.predict(image)
|
36 |
+
predicted_class = classes[int(tf.argmax(prediction, axis=1))]
|
37 |
+
confidence = tf.reduce_max(prediction).numpy()
|
38 |
return predicted_class, confidence
|
39 |
|
40 |
iface = gr.Interface(
|
requirements.txt
CHANGED
@@ -1,97 +1,3 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
annotated-types==0.6.0
|
5 |
-
anyio==3.7.1
|
6 |
-
astunparse==1.6.3
|
7 |
-
attrs==23.1.0
|
8 |
-
cachetools==5.3.2
|
9 |
-
certifi==2023.7.22
|
10 |
-
charset-normalizer==3.3.2
|
11 |
-
click==8.1.7
|
12 |
-
colorama==0.4.6
|
13 |
-
contourpy==1.2.0
|
14 |
-
cycler==0.12.1
|
15 |
-
exceptiongroup==1.1.3
|
16 |
-
fastapi==0.104.1
|
17 |
-
ffmpy==0.3.1
|
18 |
-
filelock==3.13.1
|
19 |
-
flatbuffers==23.5.26
|
20 |
-
fonttools==4.44.0
|
21 |
-
fsspec==2023.10.0
|
22 |
-
gast==0.5.4
|
23 |
-
google-auth==2.23.4
|
24 |
-
google-auth-oauthlib==1.0.0
|
25 |
-
google-pasta==0.2.0
|
26 |
-
gradio==4.1.2
|
27 |
-
gradio_client==0.7.0
|
28 |
-
grpcio==1.59.2
|
29 |
-
h11==0.14.0
|
30 |
-
h5py==3.10.0
|
31 |
-
httpcore==1.0.1
|
32 |
-
httpx==0.25.1
|
33 |
-
huggingface-hub==0.19.0
|
34 |
-
idna==3.4
|
35 |
-
importlib-metadata==6.8.0
|
36 |
-
importlib-resources==6.1.1
|
37 |
-
Jinja2==3.1.2
|
38 |
-
jsonschema==4.19.2
|
39 |
-
jsonschema-specifications==2023.7.1
|
40 |
-
keras==2.14.0
|
41 |
-
kiwisolver==1.4.5
|
42 |
-
libclang==16.0.6
|
43 |
-
Markdown==3.5.1
|
44 |
-
markdown-it-py==3.0.0
|
45 |
-
MarkupSafe==2.1.3
|
46 |
-
matplotlib==3.8.1
|
47 |
-
mdurl==0.1.2
|
48 |
-
ml-dtypes==0.2.0
|
49 |
-
numpy==1.26.1
|
50 |
-
oauthlib==3.2.2
|
51 |
-
opt-einsum==3.3.0
|
52 |
-
orjson==3.9.10
|
53 |
-
packaging==23.2
|
54 |
-
pandas==2.1.2
|
55 |
-
Pillow==10.1.0
|
56 |
-
protobuf==4.25.0
|
57 |
-
pyasn1==0.5.0
|
58 |
-
pyasn1-modules==0.3.0
|
59 |
-
pydantic==2.4.2
|
60 |
-
pydantic_core==2.10.1
|
61 |
-
pydub==0.25.1
|
62 |
-
Pygments==2.16.1
|
63 |
-
pyparsing==3.1.1
|
64 |
-
python-dateutil==2.8.2
|
65 |
-
python-multipart==0.0.6
|
66 |
-
pytz==2023.3.post1
|
67 |
-
PyYAML==6.0.1
|
68 |
-
referencing==0.30.2
|
69 |
-
requests==2.31.0
|
70 |
-
requests-oauthlib==1.3.1
|
71 |
-
rich==13.6.0
|
72 |
-
rpds-py==0.12.0
|
73 |
-
rsa==4.9
|
74 |
-
semantic-version==2.10.0
|
75 |
-
shellingham==1.5.4
|
76 |
-
six==1.16.0
|
77 |
-
sniffio==1.3.0
|
78 |
-
starlette==0.27.0
|
79 |
-
tensorboard==2.14.1
|
80 |
-
tensorboard-data-server==0.7.2
|
81 |
-
tensorflow==2.14.0
|
82 |
-
tensorflow-estimator==2.14.0
|
83 |
-
tensorflow-intel==2.14.0
|
84 |
-
tensorflow-io-gcs-filesystem==0.31.0
|
85 |
-
termcolor==2.3.0
|
86 |
-
tomlkit==0.12.0
|
87 |
-
toolz==0.12.0
|
88 |
-
tqdm==4.66.1
|
89 |
-
typer==0.9.0
|
90 |
-
typing_extensions==4.8.0
|
91 |
-
tzdata==2023.3
|
92 |
-
urllib3==2.0.7
|
93 |
-
uvicorn==0.24.0.post1
|
94 |
-
websockets==11.0.3
|
95 |
-
Werkzeug==3.0.1
|
96 |
-
wrapt==1.14.1
|
97 |
-
zipp==3.17.0
|
|
|
1 |
+
python==3.9
|
2 |
+
tensorflow
|
3 |
+
gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|