mertbozkurt commited on
Commit
ace3b59
·
1 Parent(s): 9be9329
Files changed (12) hide show
  1. Dockerfile +9 -0
  2. LICENSE +21 -0
  3. Procfile +1 -0
  4. catvsdog.py +37 -0
  5. disaster_twet.py +56 -0
  6. face_detec.py +48 -0
  7. models/data1.csv +0 -0
  8. movie_rec.py +72 -0
  9. requirements.txt +11 -0
  10. runtime.txt +1 -0
  11. setup.sh +9 -0
  12. streamlit_app.py +39 -0
Dockerfile ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.8
2
+
3
+ WORKDIR /deeplearning_models_heroku
4
+ ADD models /deeplearning_models_heroku/models
5
+ ADD streamlit_app.py .
6
+
7
+ RUN pip install numpy tensorflow-cpu opencv-python-headless streamlit Pillow scikit-learn pandas pickleshare keras requests flask
8
+
9
+ CMD ["streamlit", "run" ,"./streamlit_app.py"]
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Mert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Procfile ADDED
@@ -0,0 +1 @@
 
 
1
+ web: sh setup.sh && streamlit run streamlit_app.py
catvsdog.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ import cv2
5
+ from PIL import Image
6
+
7
+ def main_catvsdog():
8
+
9
+ st.header("Cats Vs Dogs")
10
+ model = tf.keras.models.load_model("models/catsVSdogs.h5")
11
+
12
+ image_file = st.file_uploader(
13
+ "Upload image for testing", type=['jpeg', 'png', 'jpg', 'webp'])
14
+
15
+ if st.button("Process"):
16
+ image = Image.open(image_file)
17
+ #image = cv2.imread (image_file)
18
+ image = np.array(image.convert('RGB'))
19
+ image = cv2.resize(image, (224, 224))
20
+ image = np.reshape(image, [1, 224, 224, 3])
21
+
22
+ FRAME_WINDOW = st.image([])
23
+
24
+ classes = model.predict(image)
25
+ if classes > 0.5:
26
+ st.header("Dog")
27
+ st.subheader(classes)
28
+ if classes < 0.5:
29
+ st.header("Cat")
30
+ st.subheader(1-classes)
31
+
32
+ image1 = Image.open(image_file)
33
+ FRAME_WINDOW.image(image1)
34
+
35
+
36
+ if __name__ == '__main__':
37
+ main_catvsdog()
disaster_twet.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import streamlit as st
3
+ import pickle
4
+ from sklearn import model_selection
5
+ from sklearn.feature_extraction.text import CountVectorizer
6
+
7
+ def main_twet():
8
+
9
+ st.header("Disaster Tweet Classification")
10
+ filename = 'models/finalized_model.sav'
11
+ loaded_model = pickle.load(open(filename, 'rb'))
12
+ data1 = pd.read_csv("models/data1.csv")
13
+
14
+ train_x, test_x, train_y, test_y = model_selection.train_test_split(data1["text"],
15
+ data1["target"], random_state=42)
16
+
17
+ sentences = ["Just happened a terrible car crash",
18
+ "We're shaking...It's an earthquake",
19
+ "there is a forest fire at spot pond, geese are fleeing across the street, I cannot save them all",
20
+ "Paradise ,the bitches say im hot i say no bitch im blazing",
21
+ "Refugio oil spill may have been costlier bigger than projected",
22
+ "someone hold my hand and tell me ITS OKAY because I am having a panic attack for no reason"
23
+ ]
24
+
25
+ option = st.selectbox(
26
+ 'You can select here', sentences)
27
+
28
+ if st.button("Process from select box"):
29
+ option = pd.Series(option)
30
+ vectorizer = CountVectorizer()
31
+ vectorizer.fit(train_x)
32
+ option = vectorizer.transform(option)
33
+ result = loaded_model.predict(option)
34
+ if result == 1:
35
+ st.header("Disaster")
36
+ if result == 0:
37
+ st.header("Not Disaster")
38
+
39
+ input = st.text_input("Custom text")
40
+
41
+ if st.button("Process custom text"):
42
+ input = pd.Series(input)
43
+ vectorizer = CountVectorizer()
44
+ vectorizer.fit(train_x)
45
+ input = vectorizer.transform(input)
46
+ result = loaded_model.predict(input)
47
+
48
+ if result == 1:
49
+ st.header("Disaster")
50
+
51
+ if result == 0:
52
+ st.header("Not Disaster")
53
+
54
+
55
+ if __name__ == '__main__':
56
+ main_twet()
face_detec.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ from PIL import Image,ImageEnhance
4
+ import numpy as np
5
+ import os
6
+
7
+ face_cascade = cv2.CascadeClassifier('models/haarcascade_frontalface_default.xml')
8
+ eye_cascade = cv2.CascadeClassifier('models/haarcascade_eye.xml')
9
+ smile_cascade = cv2.CascadeClassifier('models/haarcascade_smile.xml')
10
+
11
+ @st.cache
12
+ def load_image(img):
13
+ im = Image.open(img)
14
+ return im
15
+
16
+ def detect_faces(our_image):
17
+ new_img = np.array(our_image.convert('RGB'))
18
+ img = cv2.cvtColor(new_img,1)
19
+ gray = cv2.cvtColor(new_img, cv2.COLOR_BGR2GRAY)
20
+ # Detect faces
21
+ faces = face_cascade.detectMultiScale(gray, 1.1, 4)
22
+ # Draw rectangle around the faces
23
+ for (x, y, w, h) in faces:
24
+ cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
25
+ return img,faces
26
+
27
+ def main_face():
28
+
29
+ st.title("Face Detection App")
30
+ image_file = st.file_uploader("Upload Image",type=['jpg','png','jpeg'])
31
+
32
+ if image_file is not None:
33
+ our_image = Image.open(image_file)
34
+ st.text("Original Image")
35
+ # st.write(type(our_image))
36
+ st.image(our_image,width=300)
37
+
38
+ if st.button("Process"):
39
+ result_img,result_faces = detect_faces(our_image)
40
+ st.image(result_img)
41
+
42
+ st.success("Found {} faces".format(len(result_faces)))
43
+ #elif feature_choice == 'Smiles':
44
+ # result_img = detect_smiles(our_image)
45
+ # st.image(result_img)
46
+
47
+ if __name__ == '__main__':
48
+ main_face()
models/data1.csv ADDED
The diff for this file is too large to render. See raw diff
 
movie_rec.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import _pickle as cPickle
2
+ import bz2
3
+ import pickle
4
+ import streamlit as st
5
+ import requests
6
+
7
+ def decompress_pickle(file):
8
+ data = bz2.BZ2File(file, "rb")
9
+ data = cPickle.load(data)
10
+ return data
11
+
12
+ movies = pickle.load(open('models/movie_list.pkl', 'rb'))
13
+ similarity = decompress_pickle('models/similarity.pbz2')
14
+
15
+ def fetch_poster(movie_id):
16
+
17
+ url = "https://api.themoviedb.org/3/movie/{}?api_key=8265bd1679663a7ea12ac168da84d2e8&language=en-US".format(
18
+ movie_id)
19
+ data = requests.get(url)
20
+ data = data.json()
21
+ poster_path = data['poster_path']
22
+ full_path = "https://image.tmdb.org/t/p/w500/" + poster_path
23
+ return full_path
24
+
25
+
26
+ def recommend(movie):
27
+ index = movies[movies['title'] == movie].index[0]
28
+ distances = sorted(
29
+ list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1])
30
+ recommended_movie_names = []
31
+ recommended_movie_posters = []
32
+ for i in distances[1:6]:
33
+ # fetch the movie poster
34
+ movie_id = movies.iloc[i[0]].movie_id
35
+ recommended_movie_posters.append(fetch_poster(movie_id))
36
+ recommended_movie_names.append(movies.iloc[i[0]].title)
37
+
38
+ return recommended_movie_names, recommended_movie_posters
39
+
40
+ def main_movie() :
41
+
42
+ st.header('Movie Recommender System')
43
+ movie_list = movies['title'].values
44
+ selected_movie = st.selectbox(
45
+ "Type or select a movie from the dropdown",
46
+ movie_list
47
+ )
48
+
49
+ if st.button('Show Recommendation'):
50
+ recommended_movie_names, recommended_movie_posters = recommend(selected_movie)
51
+ col1, col2, col3, col4, col5 = st.columns(5)
52
+ with col1:
53
+ st.text(recommended_movie_names[0])
54
+ st.image(recommended_movie_posters[0])
55
+ with col2:
56
+ st.text(recommended_movie_names[1])
57
+ st.image(recommended_movie_posters[1])
58
+ with col3:
59
+ st.text(recommended_movie_names[2])
60
+ st.image(recommended_movie_posters[2])
61
+ with col4:
62
+ st.text(recommended_movie_names[3])
63
+ st.image(recommended_movie_posters[3])
64
+ with col5:
65
+ st.text(recommended_movie_names[4])
66
+ st.image(recommended_movie_posters[4])
67
+
68
+
69
+
70
+ if __name__ == '__main__':
71
+ main_movie()
72
+
requirements.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ numpy == 1.23.1
2
+ tensorflow-cpu==2.9.1
3
+ opencv-python-headless==4.4.0.42
4
+ streamlit == 1.11.0
5
+ Pillow== 9.2.0
6
+ scikit-learn==0.23.1
7
+ pandas == 1.4.3
8
+ pickleshare == 0.7.5
9
+ keras == 2.9.0
10
+ requests == 2.24.0
11
+ tensorflow-hub == 0.12.0
runtime.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ python-3.8.8
setup.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ mkdir -p ~/.streamlit/
2
+
3
+ echo "\
4
+ [server]\n\
5
+ port = $PORT\n\
6
+ enableCORS = false\n\
7
+ headless = true\n\
8
+ \n\
9
+ " > ~/.streamlit/config.toml
streamlit_app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import pandas as pd
4
+ from face_detec import main_face
5
+ from movie_rec import main_movie
6
+ from disaster_twet import main_twet
7
+ from catvsdog import main_catvsdog
8
+
9
+ os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
10
+ # -------------------------------------------------------------------------------------------------------------
11
+ def main():
12
+ st.set_page_config(layout="wide")
13
+ st.write("")
14
+ st.sidebar.write("")
15
+ st.sidebar.write("")
16
+ st.sidebar.write("")
17
+ st.sidebar.write("")
18
+ st.sidebar.subheader("Select an option")
19
+ activities = [
20
+ "Cats vs Dogs", "Disaster Tweet Classification", "Movie Recommender", "Face Detection"]
21
+ choice = st.sidebar.selectbox("", activities)
22
+
23
+ # ------------Cats Vs Dogs ----------------------------------------------------------------
24
+
25
+ if choice == "Cats vs Dogs":
26
+ main_catvsdog()
27
+ # ------------------------------------------------------------------------
28
+ if choice == "Disaster Tweet Classification":
29
+ main_twet()
30
+
31
+ # ----------------------------------------------------------------------------------------------------------------
32
+ if choice == "Movie Recommender":
33
+ main_movie()
34
+ # -------------------------------------------------------------------------------
35
+ if choice == "Face Detection":
36
+ main_face()
37
+
38
+ if __name__ == '__main__':
39
+ main()