Spaces:
Runtime error
Runtime error
trying a different model
Browse files- .DS_Store +0 -0
- .gitattributes +1 -0
- README.md +7 -31
- app.py +46 -7
- categories.txt +1 -1
- cheetah.jpeg +0 -0
- info.txt +0 -9
- model.h5 +1 -1
- model_test.h5 +3 -0
- pug.jpeg +0 -0
- reader.py +0 -79
- requirements.txt +2 -2
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
.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_test.h5 filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,37 +1,13 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
|
|
7 |
app_file: app.py
|
8 |
pinned: false
|
|
|
9 |
---
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
`title`: _string_
|
14 |
-
Display title for the Space
|
15 |
-
|
16 |
-
`emoji`: _string_
|
17 |
-
Space emoji (emoji-only character allowed)
|
18 |
-
|
19 |
-
`colorFrom`: _string_
|
20 |
-
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
21 |
-
|
22 |
-
`colorTo`: _string_
|
23 |
-
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
24 |
-
|
25 |
-
`sdk`: _string_
|
26 |
-
Can be either `gradio` or `streamlit`
|
27 |
-
|
28 |
-
`sdk_version` : _string_
|
29 |
-
Only applicable for `streamlit` SDK.
|
30 |
-
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
|
31 |
-
|
32 |
-
`app_file`: _string_
|
33 |
-
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
|
34 |
-
Path is relative to the root of the repository.
|
35 |
-
|
36 |
-
`pinned`: _boolean_
|
37 |
-
Whether the Space stays on top of your list.
|
|
|
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
|
9 |
pinned: false
|
10 |
+
license: mit
|
11 |
---
|
12 |
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -5,12 +5,11 @@ import gradio as gr
|
|
5 |
import numpy as np
|
6 |
import os
|
7 |
from tensorflow.keras.models import load_model
|
8 |
-
from reader import get_article
|
9 |
|
10 |
### -------------------------------- ###
|
11 |
### model loading ###
|
12 |
### -------------------------------- ###
|
13 |
-
model = load_model('
|
14 |
|
15 |
## --------------------------------- ###
|
16 |
### reading: categories.txt ###
|
@@ -23,15 +22,55 @@ if os.path.isfile("categories.txt"):
|
|
23 |
labels = categories.readline().split()
|
24 |
|
25 |
## --------------------------------- ###
|
26 |
-
###
|
27 |
### -------------------------------- ###
|
28 |
# borrow file reading functionality from reader.py
|
29 |
-
info =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
### -------------------------------- ###
|
32 |
### interface creation ###
|
33 |
### -------------------------------- ###
|
34 |
-
samples = ['
|
35 |
|
36 |
def preprocess(image):
|
37 |
image = np.array(image) / 255
|
@@ -51,5 +90,5 @@ image = gr.inputs.Image(shape=(300, 300), label="Upload Your Image Here")
|
|
51 |
label = gr.outputs.Label(num_top_classes=len(labels))
|
52 |
|
53 |
# generate and launch interface
|
54 |
-
interface = gr.Interface(fn=predict_image, inputs=image, outputs=label, article=
|
55 |
-
interface.launch()
|
|
|
5 |
import numpy as np
|
6 |
import os
|
7 |
from tensorflow.keras.models import load_model
|
|
|
8 |
|
9 |
### -------------------------------- ###
|
10 |
### model loading ###
|
11 |
### -------------------------------- ###
|
12 |
+
model = load_model('model_test.h5') # single file model from colab
|
13 |
|
14 |
## --------------------------------- ###
|
15 |
### reading: categories.txt ###
|
|
|
22 |
labels = categories.readline().split()
|
23 |
|
24 |
## --------------------------------- ###
|
25 |
+
### rendering: info.html ###
|
26 |
### -------------------------------- ###
|
27 |
# borrow file reading functionality from reader.py
|
28 |
+
# info =
|
29 |
+
description = "A Hugging Space demo created by datasith"
|
30 |
+
title = "Cast parts: Deffective or Okay?"
|
31 |
+
# css = \
|
32 |
+
# '''
|
33 |
+
# .div {
|
34 |
+
# border: 2px solid black;
|
35 |
+
# margin: 10px;
|
36 |
+
# padding: 5%;
|
37 |
+
# }
|
38 |
+
# ul {
|
39 |
+
# display: inline-block;
|
40 |
+
# text-align: left;
|
41 |
+
# }
|
42 |
+
# img {
|
43 |
+
# display: block;
|
44 |
+
# margin: auto;
|
45 |
+
# }
|
46 |
+
# .description {
|
47 |
+
# text-align: center;
|
48 |
+
# }
|
49 |
+
# '''
|
50 |
+
|
51 |
+
article = \
|
52 |
+
'''
|
53 |
+
#### Deffective or Okay?
|
54 |
+
|
55 |
+
Demo app including a binary classification model for casted parts
|
56 |
+
This is a test project to get familiar with Hugging Face!
|
57 |
+
The space includes the necessary files for everything to run smoothly on HF's Spaces:
|
58 |
+
|
59 |
+
- app.py
|
60 |
+
- reader.py
|
61 |
+
- requirements.txt
|
62 |
+
- model.h5 (TensorFlow/Keras)
|
63 |
+
- categories.txt
|
64 |
+
- info.txt
|
65 |
+
|
66 |
+
The data used to train the model is available as [Kaggle dataset](https://www.kaggle.com/datasets/ravirajsinh45/real-life-industrial-dataset-of-casting-product).
|
67 |
+
The space was inspired by @Isabel's wonderful [cat or pug](https://huggingface.co/spaces/isabel/pug-or-cat-image-classifier) one. Enjoy!d
|
68 |
+
'''
|
69 |
|
70 |
### -------------------------------- ###
|
71 |
### interface creation ###
|
72 |
### -------------------------------- ###
|
73 |
+
samples = ['defective.jpeg', 'okay.jpeg']
|
74 |
|
75 |
def preprocess(image):
|
76 |
image = np.array(image) / 255
|
|
|
90 |
label = gr.outputs.Label(num_top_classes=len(labels))
|
91 |
|
92 |
# generate and launch interface
|
93 |
+
interface = gr.Interface(fn=predict_image, inputs=image, outputs=label, article=article, theme='default', title=title, allow_flagging='never', description=description, examples=samples)
|
94 |
+
interface.launch()
|
categories.txt
CHANGED
@@ -1 +1 @@
|
|
1 |
-
|
|
|
1 |
+
def_front ok_front
|
cheetah.jpeg
DELETED
Binary file (130 kB)
|
|
info.txt
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
Isabel
|
2 |
-
Cat or pug? A Helpful App for the Species-Confused
|
3 |
-
This is a test project to see what students might be able to produce and host permanently as their final project! Students do NOT need to edit or interact with code in any way, although they can view (and even edit) it if they would like to. The interface above is generated automatically based students' data. Students collect data themselves and complete the project writeup (including this description and the info below). We provide `app.py`, `reader.py`, and `requirements.txt`, while students provide `model.h5`, which is produced by a single-block Colab notebook and directly downloaded from a student's google drive; `categories.txt` which includes the different images category names on a single line; and `info.txt`, which they can create in Hugging Face or upload directly as a plaintext file.
|
4 |
-
The data for this model was collected from my camera roll over the past couple of years. I have a lot of pug and cat pictures. This was a quick test to see whether the model generalizes over number of categories
|
5 |
-
How does our model take into account data privacy? I own this data and I can give whatever permission I would like to use it :>
|
6 |
-
How does our model address the issue of bias in AI? It's important to develop sensitive AI models. More explanation is needed here.
|
7 |
-
How does our model relate to the future of work or human identity? Something something.
|
8 |
-
http://justfunfacts.com/wp-content/uploads/2018/12/chinchillas.jpg
|
9 |
-
My teammates were these chinchillas! What a talented group.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model.h5
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
size 134670360
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:aacf5ddc63a89f828b15fbb0fe87b7c28fce1b521271fe7a2ac563809ac23a9c
|
3 |
size 134670360
|
model_test.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:21c73dae526f60eedb1ee9645e0575917b3c86345324ca9018d8128c442e3ce0
|
3 |
+
size 221962152
|
pug.jpeg
DELETED
Binary file (6.14 kB)
|
|
reader.py
DELETED
@@ -1,79 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
from yattag import Doc
|
3 |
-
|
4 |
-
## --------------------------------- ###
|
5 |
-
### reading: info.txt ###
|
6 |
-
### -------------------------------- ###
|
7 |
-
# placeholders in case info.txt does not exist
|
8 |
-
|
9 |
-
def get_article():
|
10 |
-
filename = "info.txt"
|
11 |
-
placeholder = "please create an info.txt to customize this text"
|
12 |
-
|
13 |
-
title = bkgd = data_collection = priv_cons = bias_cons = ident_cons = img_src = membs = placeholder
|
14 |
-
# check if info.txt is present
|
15 |
-
if os.path.isfile(filename):
|
16 |
-
# open info.txt in read mode
|
17 |
-
info = open(filename, "r")
|
18 |
-
|
19 |
-
# read each line to a string
|
20 |
-
description = "An AI project created by " + info.readline()
|
21 |
-
title = info.readline()
|
22 |
-
bkgd = info.readline()
|
23 |
-
data_collection = info.readline()
|
24 |
-
priv_cons = info.readline()
|
25 |
-
bias_cons = info.readline()
|
26 |
-
ident_cons = info.readline()
|
27 |
-
img_src = info.readline()
|
28 |
-
membs = info.readline()
|
29 |
-
|
30 |
-
# close file
|
31 |
-
info.close()
|
32 |
-
|
33 |
-
# use yattag library to generate html
|
34 |
-
doc, tag, text, line = Doc().ttl()
|
35 |
-
# create html based on info.txt
|
36 |
-
with tag('div'):
|
37 |
-
with tag('div', klass='my-div'):
|
38 |
-
line('h2', 'Project Background')
|
39 |
-
line('p', bkgd)
|
40 |
-
with tag('div', klass='my-div'):
|
41 |
-
line('h2', 'Data Collection')
|
42 |
-
line('p', data_collection)
|
43 |
-
with tag('div', klass='my-div'):
|
44 |
-
line('h2', 'Ethical Considerations')
|
45 |
-
with tag('ul'):
|
46 |
-
line('li', priv_cons)
|
47 |
-
line('li', bias_cons)
|
48 |
-
line('li', ident_cons)
|
49 |
-
with tag('div', klass='my-div'):
|
50 |
-
line('h2', 'Our Team')
|
51 |
-
line('p', membs)
|
52 |
-
doc.stag('img', src=img_src)
|
53 |
-
|
54 |
-
css = '''
|
55 |
-
.my-div {
|
56 |
-
border: 2px solid black;
|
57 |
-
text-align: center;
|
58 |
-
margin: 10px;
|
59 |
-
padding: 5%;
|
60 |
-
}
|
61 |
-
ul {
|
62 |
-
display: inline-block;
|
63 |
-
text-align: left;
|
64 |
-
}
|
65 |
-
img {
|
66 |
-
display: block;
|
67 |
-
margin: auto;
|
68 |
-
}
|
69 |
-
.description {
|
70 |
-
text-align: center;
|
71 |
-
}
|
72 |
-
'''
|
73 |
-
|
74 |
-
return {
|
75 |
-
'article': doc.getvalue(),
|
76 |
-
'css': css,
|
77 |
-
'title': title,
|
78 |
-
'description': description,
|
79 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
-
tensorflow
|
2 |
-
keras
|
3 |
yattag==1.14.0
|
|
|
1 |
+
tensorflow>=2.6.1
|
2 |
+
keras>=2.6.0
|
3 |
yattag==1.14.0
|