datasith commited on
Commit
c0b99c0
·
1 Parent(s): b7020e5

first commit

Browse files
Files changed (6) hide show
  1. .gitattributes +1 -0
  2. .gitignore +136 -0
  3. README.md +4 -4
  4. app.py +94 -0
  5. categories.txt +1 -0
  6. requirements.txt +3 -0
.gitattributes CHANGED
@@ -25,3 +25,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
27
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
27
  *tfevents* filter=lfs diff=lfs merge=lfs -text
28
+ model.h5 filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Repository specific
2
+ *datasets
3
+ .DS_Store
4
+ *.jpg
5
+ *.h5
6
+ *.jpeg
7
+
8
+ # Byte-compiled / optimized / DLL files
9
+ __pycache__/
10
+ *.py[cod]
11
+ *$py.class
12
+
13
+ # C extensions
14
+ *.so
15
+
16
+ # Distribution / packaging
17
+ .Python
18
+ build/
19
+ develop-eggs/
20
+ dist/
21
+ downloads/
22
+ eggs/
23
+ .eggs/
24
+ lib/
25
+ lib64/
26
+ parts/
27
+ sdist/
28
+ var/
29
+ wheels/
30
+ pip-wheel-metadata/
31
+ share/python-wheels/
32
+ *.egg-info/
33
+ .installed.cfg
34
+ *.egg
35
+ MANIFEST
36
+
37
+ # PyInstaller
38
+ # Usually these files are written by a python script from a template
39
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
40
+ *.manifest
41
+ *.spec
42
+
43
+ # Installer logs
44
+ pip-log.txt
45
+ pip-delete-this-directory.txt
46
+
47
+ # Unit test / coverage reports
48
+ htmlcov/
49
+ .tox/
50
+ .nox/
51
+ .coverage
52
+ .coverage.*
53
+ .cache
54
+ nosetests.xml
55
+ coverage.xml
56
+ *.cover
57
+ *.py,cover
58
+ .hypothesis/
59
+ .pytest_cache/
60
+
61
+ # Translations
62
+ *.mo
63
+ *.pot
64
+
65
+ # Django stuff:
66
+ *.log
67
+ local_settings.py
68
+ db.sqlite3
69
+ db.sqlite3-journal
70
+
71
+ # Flask stuff:
72
+ instance/
73
+ .webassets-cache
74
+
75
+ # Scrapy stuff:
76
+ .scrapy
77
+
78
+ # Sphinx documentation
79
+ docs/_build/
80
+
81
+ # PyBuilder
82
+ target/
83
+
84
+ # Jupyter Notebook
85
+ .ipynb_checkpoints
86
+
87
+ # IPython
88
+ profile_default/
89
+ ipython_config.py
90
+
91
+ # pyenv
92
+ .python-version
93
+
94
+ # pipenv
95
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
97
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
98
+ # install all needed dependencies.
99
+ #Pipfile.lock
100
+
101
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
102
+ __pypackages__/
103
+
104
+ # Celery stuff
105
+ celerybeat-schedule
106
+ celerybeat.pid
107
+
108
+ # SageMath parsed files
109
+ *.sage.py
110
+
111
+ # Environments
112
+ .env
113
+ .venv
114
+ env/
115
+ venv/
116
+ ENV/
117
+ env.bak/
118
+ venv.bak/
119
+
120
+ # Spyder project settings
121
+ .spyderproject
122
+ .spyproject
123
+
124
+ # Rope project settings
125
+ .ropeproject
126
+
127
+ # mkdocs documentation
128
+ /site
129
+
130
+ # mypy
131
+ .mypy_cache/
132
+ .dmypy.json
133
+ dmypy.json
134
+
135
+ # Pyre type checker
136
+ .pyre/
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: Hot Dog Not Hot Dog
3
- emoji: 🌖
4
- colorFrom: indigo
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 2.8.14
8
  app_file: app.py
 
1
  ---
2
+ title: Image Classification Cast Parts
3
+ emoji: 🏃
4
+ colorFrom: green
5
+ colorTo: red
6
  sdk: gradio
7
  sdk_version: 2.8.14
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### -------------------------------- ###
2
+ ### libraries ###
3
+ ### -------------------------------- ###
4
+ import gradio as gr
5
+ import numpy as np
6
+ import os
7
+ import tensorflow as tf
8
+
9
+ ### -------------------------------- ###
10
+ ### model loading ###
11
+ ### -------------------------------- ###
12
+ model = tf.keras.models.load_model('model.h5')
13
+
14
+ ## --------------------------------- ###
15
+ ### reading: categories.txt ###
16
+ ### -------------------------------- ###
17
+ labels = ['please upload categories.txt' for i in range(10)] # placeholder
18
+
19
+ if os.path.isfile("categories.txt"):
20
+ # open categories.txt in read mode
21
+ categories = open("categories.txt", "r")
22
+ labels = categories.readline().split()
23
+
24
+ ## --------------------------------- ###
25
+ ### page description ###
26
+ ### -------------------------------- ###
27
+ title = "Seefood: Hot dog or... not hot dog"
28
+ description = "A Hugging Space demo created by datasith!"
29
+ article = \
30
+ '''
31
+ #### Hot dog or not hot dog
32
+
33
+ Jìan-Yang's masterpiece from the show Silicon Valley serves as a great exercise to get
34
+ familiar with Hugging Face spaces! All the necessary files are included for everything
35
+ to run smoothly on HF's Spaces:
36
+
37
+ - app.py
38
+ - reader.py
39
+ - requirements.txt
40
+ - model.h5 (TensorFlow/Keras)
41
+ - categories.txt
42
+ - info.txt
43
+
44
+ The data used to train the model is available as a
45
+ [Kaggle dataset](https://www.kaggle.com/datasets/dansbecker/hot-dog-not-hot-dog).
46
+ The step-by-step process for generating, training, and testing the Image Classification model is
47
+ available at my [GitHub respository](https://github.com/datasith/ds-experiments-image-classification/tree/main/hotdog-not-hotdog).
48
+
49
+ If you enjoy my work feel free to follow me here on HF and/or on:
50
+
51
+ - [GitHub](https://github.com/datasith)
52
+ - [Kaggle](https://kaggle.com/datasith)
53
+ - [Twitter](https://twitter.com/datasith)
54
+ - [LinkedIn](https://linkedin.com/in/datasith)
55
+
56
+ Either way, enjoy!
57
+ '''
58
+
59
+ ### -------------------------------- ###
60
+ ### interface creation ###
61
+ ### -------------------------------- ###
62
+ samples = ['yay.jpg', 'nay.jpg']
63
+
64
+ def preprocess(image):
65
+ image = tf.image.resize(image, [512, 512])
66
+ img_array = tf.keras.utils.img_to_array(image)
67
+ img_array = tf.expand_dims(img_array, 0)
68
+ # image = np.array(image) / 255
69
+ # image = np.expand_dims(image, axis=0)
70
+ return img_array
71
+
72
+ def predict_image(image):
73
+ # pred = model.predict(preprocess(image))
74
+ # results = {}
75
+ # for row in pred:
76
+ # for idx, item in enumerate(row):
77
+ # results[labels[idx]] = float(item)
78
+ predictions = model.predict(preprocess(image))
79
+ scores = tf.nn.softmax(predictions[0])
80
+ results = {}
81
+ for idx, res in enumerate(scores):
82
+ results[labels[idx]] = float(res)
83
+ return results
84
+
85
+ # generate img input and text label output
86
+ image = gr.inputs.Image(shape=(300, 300), label="Upload Your Image Here")
87
+ label = gr.outputs.Label(num_top_classes=len(labels))
88
+
89
+ # generate and launch interface
90
+ interface = gr.Interface(fn=predict_image, inputs=image,
91
+ outputs=label, article=article, theme='default',
92
+ title=title, allow_flagging='never', description=description,
93
+ examples=samples)
94
+ interface.launch()
categories.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Hot-dog Not-hot-dog
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ tensorflow>=2.6.1
2
+ keras>=2.6.0
3
+ yattag==1.14.0