sreya1905 commited on
Commit
4115037
·
1 Parent(s): 0844af7

Upload 8 files

Browse files
Files changed (9) hide show
  1. .gitattributes +4 -0
  2. BP.pkl +3 -0
  3. CN.keras +3 -0
  4. DP.keras +3 -0
  5. LS.keras +3 -0
  6. PP.pkl +3 -0
  7. RN.keras +3 -0
  8. Streamlit.py +162 -0
  9. requirements.txt +5 -0
.gitattributes CHANGED
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ CN.keras filter=lfs diff=lfs merge=lfs -text
37
+ DP.keras filter=lfs diff=lfs merge=lfs -text
38
+ LS.keras filter=lfs diff=lfs merge=lfs -text
39
+ RN.keras filter=lfs diff=lfs merge=lfs -text
BP.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ff7a191c4476cc22a864ea6db1b84c43f72d25a45ad4fb60a9e482c6b261f1bf
3
+ size 4300
CN.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:24d5dfe6488acde49c807556d67b8e52332a61d9b25f549950a89ac4b3dde6a1
3
+ size 391803285
DP.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:686087ababc32e7449d113ee0bf41e1a873d7b4d2683e0af69cfce80934d73ca
3
+ size 10723181
LS.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:705ae60751f9f288daf9486f5b3535e437fd7aabb96c5b79f908e7f5e68c9b02
3
+ size 4194296
PP.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d490b9361db03dbd503b6a1424976d05a9865eefe505327b2ad342b989737eba
3
+ size 2264
RN.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56f772e386a259788dabcb7189fbe4327b3a31924fd0104e9d52c1c626101262
3
+ size 1548448
Streamlit.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ from PIL import Image
4
+ from tensorflow.keras.models import load_model
5
+ from tensorflow.keras.datasets import imdb
6
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
7
+ import pickle
8
+
9
+ # Load word index for Sentiment Classification
10
+ word_to_index = imdb.get_word_index()
11
+
12
+ # Function to perform sentiment classification
13
+ def sentiment_classification(new_review_text, model):
14
+ max_review_length = 500
15
+ new_review_tokens = [word_to_index.get(word, 0) for word in new_review_text.split()]
16
+ new_review_tokens = pad_sequences([new_review_tokens], maxlen=max_review_length)
17
+ prediction = model.predict(new_review_tokens)
18
+ if type(prediction) == list:
19
+ prediction = prediction[0]
20
+ return "Positive" if prediction > 0.5 else "Negative"
21
+
22
+ # Function to perform tumor detection
23
+ def tumor_detection(img, model):
24
+ img = Image.open(img)
25
+ img = img.resize((128, 128))
26
+ img = np.array(img)
27
+ input_img = np.expand_dims(img, axis=0)
28
+ res = model.predict(input_img)
29
+ return "Tumor Detected" if res else "No Tumor"
30
+
31
+ # Streamlit App
32
+ st.title("Deep Prediction Hub")
33
+ st.sidebar.header("Options")
34
+
35
+ # Choose between tasks
36
+ task = st.sidebar.radio("Select Task", ("Sentiment Classification", "Tumor Detection"))
37
+
38
+ if task == "Sentiment Classification":
39
+ st.subheader("Sentiment Classification")
40
+ # Input box for new review
41
+ new_review_text = st.text_area("Enter a New Review:", value="")
42
+ if st.button("Submit") and not new_review_text.strip():
43
+ st.warning("Please enter a review.")
44
+
45
+ if new_review_text.strip():
46
+ st.subheader("Choose Model for Sentiment Classification")
47
+ model_option = st.selectbox("Select Model", ("Perceptron", "Backpropagation", "DNN", "RNN", "LSTM"))
48
+
49
+ # Load models dynamically based on the selected option
50
+ if model_option == "Perceptron":
51
+ with open('PP.pkl', 'rb') as file:
52
+ model = pickle.load(file)
53
+ elif model_option == "Backpropagation":
54
+ with open('BP.pkl', 'rb') as file:
55
+ model = pickle.load(file)
56
+ elif model_option == "DNN":
57
+ model = load_model('DP.keras')
58
+ elif model_option == "RNN":
59
+ model = load_model('RN.keras')
60
+ elif model_option == "LSTM":
61
+ model = load_model('LS.keras')
62
+
63
+ if st.button("Classify Sentiment"):
64
+ result = sentiment_classification(new_review_text, model)
65
+ st.subheader("Sentiment Classification Result")
66
+ st.write(f"**{result}**")
67
+
68
+ elif task == "Tumor Detection":
69
+ st.subheader("Tumor Detection")
70
+ uploaded_file = st.file_uploader("Choose a tumor image...", type=["jpg", "jpeg", "png"])
71
+
72
+ if uploaded_file is not None:
73
+ # Load the tumor detection model
74
+ model = load_model('CN.keras')
75
+ st.image(uploaded_file, caption="Uploaded Image.", use_column_width=False, width=200)
76
+ st.write("")
77
+
78
+ if st.button("Detect Tumor"):
79
+ result = tumor_detection(uploaded_file, model)
80
+ st.subheader("Tumor Detection Result")
81
+ st.write(f"**{result}**")
82
+ import streamlit as st
83
+ import numpy as np
84
+ from PIL import Image
85
+ from tensorflow.keras.models import load_model
86
+ from tensorflow.keras.datasets import imdb
87
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
88
+ import pickle
89
+
90
+ # Load word index for Sentiment Classification
91
+ word_to_index = imdb.get_word_index()
92
+
93
+ # Function to perform sentiment classification
94
+ def sentiment_classification(new_review_text, model):
95
+ max_review_length = 500
96
+ new_review_tokens = [word_to_index.get(word, 0) for word in new_review_text.split()]
97
+ new_review_tokens = pad_sequences([new_review_tokens], maxlen=max_review_length)
98
+ prediction = model.predict(new_review_tokens)
99
+ if type(prediction) == list:
100
+ prediction = prediction[0]
101
+ return "Positive" if prediction > 0.5 else "Negative"
102
+
103
+ # Function to perform tumor detection
104
+ def tumor_detection(img, model):
105
+ img = Image.open(img)
106
+ img = img.resize((128, 128))
107
+ img = np.array(img)
108
+ input_img = np.expand_dims(img, axis=0)
109
+ res = model.predict(input_img)
110
+ return "Tumor Detected" if res else "No Tumor"
111
+
112
+ # Streamlit App
113
+ st.title("Deep Prediction Hub")
114
+ st.sidebar.header("Options")
115
+
116
+ # Choose between tasks
117
+ task = st.sidebar.radio("Select Task", ("Sentiment Classification", "Tumor Detection"))
118
+
119
+ if task == "Sentiment Classification":
120
+ st.subheader("Sentiment Classification")
121
+ # Input box for new review
122
+ new_review_text = st.text_area("Enter a New Review:", value="")
123
+ if st.button("Submit") and not new_review_text.strip():
124
+ st.warning("Please enter a review.")
125
+
126
+ if new_review_text.strip():
127
+ st.subheader("Choose Model for Sentiment Classification")
128
+ model_option = st.selectbox("Select Model", ("Perceptron", "Backpropagation", "DNN", "RNN", "LSTM"))
129
+
130
+ # Load models dynamically based on the selected option
131
+ if model_option == "Perceptron":
132
+ with open('PP.pkl', 'rb') as file:
133
+ model = pickle.load(file)
134
+ elif model_option == "Backpropagation":
135
+ with open('BP.pkl', 'rb') as file:
136
+ model = pickle.load(file)
137
+ elif model_option == "DNN":
138
+ model = load_model('DP.keras')
139
+ elif model_option == "RNN":
140
+ model = load_model('RN.keras')
141
+ elif model_option == "LSTM":
142
+ model = load_model('LS.keras')
143
+
144
+ if st.button("Classify Sentiment"):
145
+ result = sentiment_classification(new_review_text, model)
146
+ st.subheader("Sentiment Classification Result")
147
+ st.write(f"**{result}**")
148
+
149
+ elif task == "Tumor Detection":
150
+ st.subheader("Tumor Detection")
151
+ uploaded_file = st.file_uploader("Choose a tumor image...", type=["jpg", "jpeg", "png"])
152
+
153
+ if uploaded_file is not None:
154
+ # Load the tumor detection model
155
+ model = load_model('CN.keras')
156
+ st.image(uploaded_file, caption="Uploaded Image.", use_column_width=False, width=200)
157
+ st.write("")
158
+
159
+ if st.button("Detect Tumor"):
160
+ result = tumor_detection(uploaded_file, model)
161
+ st.subheader("Tumor Detection Result")
162
+ st.write(f"**{result}**")
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ numpy
3
+ Pillow
4
+ tensorflow
5
+ tqdm