mtutami22 commited on
Commit
9e433e2
·
verified ·
1 Parent(s): a9c2504

Upload 5 files

Browse files
Files changed (5) hide show
  1. Dockerfile +20 -20
  2. README.md +19 -19
  3. requirements.txt +2 -2
  4. src/prediction.py +78 -0
  5. src/streamlit_app.py +39 -39
Dockerfile CHANGED
@@ -1,21 +1,21 @@
1
- FROM python:3.9-slim
2
-
3
- WORKDIR /app
4
-
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- software-properties-common \
9
- git \
10
- && rm -rf /var/lib/apt/lists/*
11
-
12
- COPY requirements.txt ./
13
- COPY src/ ./src/
14
-
15
- RUN pip3 install -r requirements.txt
16
-
17
- EXPOSE 8501
18
-
19
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
20
-
21
  ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /app
4
+
5
+ RUN apt-get update && apt-get install -y \
6
+ build-essential \
7
+ curl \
8
+ software-properties-common \
9
+ git \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ COPY requirements.txt ./
13
+ COPY src/ ./src/
14
+
15
+ RUN pip3 install -r requirements.txt
16
+
17
+ EXPOSE 8501
18
+
19
+ HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
20
+
21
  ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
README.md CHANGED
@@ -1,19 +1,19 @@
1
- ---
2
- title: Type Of Cap
3
- emoji: 🚀
4
- colorFrom: red
5
- colorTo: red
6
- sdk: docker
7
- app_port: 8501
8
- tags:
9
- - streamlit
10
- pinned: false
11
- short_description: Streamlit template space
12
- ---
13
-
14
- # Welcome to Streamlit!
15
-
16
- Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
17
-
18
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
19
- forums](https://discuss.streamlit.io).
 
1
+ ---
2
+ title: Type Of Cap
3
+ emoji: 🚀
4
+ colorFrom: red
5
+ colorTo: red
6
+ sdk: docker
7
+ app_port: 8501
8
+ tags:
9
+ - streamlit
10
+ pinned: false
11
+ short_description: Streamlit template space
12
+ ---
13
+
14
+ # Welcome to Streamlit!
15
+
16
+ Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
17
+
18
+ If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
19
+ forums](https://discuss.streamlit.io).
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- altair
2
- pandas
3
  streamlit
 
1
+ altair
2
+ pandas
3
  streamlit
src/prediction.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import os
4
+ import sys
5
+ from io import BytesIO, StringIO
6
+ import pickle
7
+ import json
8
+ import tensorflow as tf
9
+ from PIL import Image
10
+ import numpy as np
11
+
12
+ # load files
13
+
14
+ model=tf.keras.models.load_model('best_model.h5')
15
+
16
+ klas = ['baseball_cap', 'beanie_hat', 'bucket_hat', 'fedora_hat', 'flat_cap']
17
+
18
+ st.title('Jenis Topi')
19
+
20
+ picup = st.file_uploader('Upload a picture', type=['jpg', 'jpeg', 'png'])
21
+
22
+ if picup is not None:
23
+ st.image(picup, caption='Uploaded Image', use_column_width=True)
24
+
25
+ if st.button('Predict'):
26
+
27
+ img = Image.open(picup).convert('RGB')
28
+ img = img.resize((400,400))
29
+ img_array = np.array(img)
30
+ img_array = np.expand_dims(img_array, axis=0)
31
+
32
+ prediction = model.predict(img_array)
33
+ pred_index = np.argmax(prediction)
34
+ pred_class = klas[pred_index]
35
+ confidence = prediction[0][pred_index]*100
36
+
37
+ st.success(f'Prediction: **{pred_class}** ({confidence:.2f}% confidence)')
38
+
39
+ # class picupload(object):
40
+
41
+ # def __init__(self):
42
+ # self.fileTypes=['jpg']
43
+
44
+ # def run(self):
45
+ # topi = st.file_uploader('Upload picture', type=self.fileTypes)
46
+ # show_file = st.empty()
47
+ # if not topi:
48
+ # show_file.info('Please upload a picture')
49
+ # return
50
+ # content = topi.getvalue()
51
+ # if isinstance(topi, BytesIO):
52
+ # show_file.image(topi)
53
+ # topi.close()
54
+
55
+ # if __name__ == '__main__':
56
+ # helper = picupload()
57
+ # helper.run()
58
+
59
+ # def run():
60
+
61
+ # with st.form(key='type-of-cap'):
62
+
63
+ # st.write('##Topi')
64
+
65
+ # topi = st.file_uploader('Upload file', type=['jpg'])
66
+ # show_topi = st.empty()
67
+
68
+ # if not topi:
69
+ # show_topi.info('Please upload a picture : {}'.format(' '.join(['jpg'])))
70
+ # return
71
+ # content = topi.getvalue()
72
+
73
+ # if isinstance(topi, BytesIO):
74
+ # show_topi.image(topi)
75
+ # topi.close()
76
+
77
+ # run()
78
+
src/streamlit_app.py CHANGED
@@ -1,40 +1,40 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
- import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
  ))
 
1
+ import altair as alt
2
+ import numpy as np
3
+ import pandas as pd
4
+ import streamlit as st
5
+
6
+ """
7
+ # Welcome to Streamlit!
8
+
9
+ Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
+ If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
+ forums](https://discuss.streamlit.io).
12
+
13
+ In the meantime, below is an example of what you can do with just a few lines of code:
14
+ """
15
+
16
+ num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
+ num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
+
19
+ indices = np.linspace(0, 1, num_points)
20
+ theta = 2 * np.pi * num_turns * indices
21
+ radius = indices
22
+
23
+ x = radius * np.cos(theta)
24
+ y = radius * np.sin(theta)
25
+
26
+ df = pd.DataFrame({
27
+ "x": x,
28
+ "y": y,
29
+ "idx": indices,
30
+ "rand": np.random.randn(num_points),
31
+ })
32
+
33
+ st.altair_chart(alt.Chart(df, height=700, width=700)
34
+ .mark_point(filled=True)
35
+ .encode(
36
+ x=alt.X("x", axis=None),
37
+ y=alt.Y("y", axis=None),
38
+ color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
+ size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
  ))