rohithjoseph commited on
Commit
910cb13
1 Parent(s): 0ebf419

Upload 9 files

Browse files
Files changed (9) hide show
  1. .gitattributes +2 -0
  2. LS.keras +3 -0
  3. PP.pkl +3 -0
  4. README.md +58 -0
  5. RN.keras +3 -0
  6. Streamlit.py +79 -0
  7. Streamlit_url.txt +1 -0
  8. main.py +51 -0
  9. requirements.txt +5 -0
.gitattributes CHANGED
@@ -34,3 +34,5 @@ saved_model/**/* 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
  DP.keras 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
  DP.keras filter=lfs diff=lfs merge=lfs -text
37
+ LS.keras filter=lfs diff=lfs merge=lfs -text
38
+ RN.keras filter=lfs diff=lfs merge=lfs -text
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
README.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Deep Prediction Hub
2
+
3
+ Overview
4
+
5
+ Welcome to Deep Prediction Hub, a Streamlit web application that provides two deep learning-based tasks: Sentiment Classification and Tumor Detection.
6
+
7
+ Tasks
8
+
9
+ 1. Sentiment Classification
10
+ This task involves classifying the sentiment of a given text into "Positive" or "Negative". Users can input a review, and the application provides the sentiment classification using various models.
11
+
12
+ 2.Tumor Detection
13
+ In Tumor Detection, users can upload an image, and the application uses a Convolutional Neural Network (CNN) model to determine if a tumor is present or not.
14
+ Getting Started
15
+
16
+ Prerequisites
17
+
18
+ Python 3.6 or higher
19
+ Required packages: streamlit, numpy, cv2, PIL, tensorflow
20
+ Pre-trained models: PP.pkl, BP.pkl, DP.keras, RN.keras, LS.keras, CN.keras
21
+ Trained IMDb word index: Ensure the IMDb word index is available for sentiment classification.
22
+
23
+ Installation
24
+
25
+ Clone the repository: git clone https://github.com/yourusername/deep-prediction-hub.git
26
+
27
+ Usage
28
+
29
+ Access the application by opening the provided URL after running the Streamlit app.
30
+
31
+ Choose between "Sentiment Classification" and "Tumor Detection" tasks.
32
+
33
+ Sentiment Classification
34
+
35
+ Enter a review in the text area.
36
+ Select a model from the dropdown.
37
+ Click "Submit" and then "Classify Sentiment."
38
+
39
+ Tumor Detection
40
+
41
+ Upload an image using the file uploader.
42
+ Click "Detect Tumor" to perform tumor detection.
43
+
44
+ Models
45
+
46
+ Perceptron (PP.pkl): Perceptron-based sentiment classification model.
47
+ Backpropagation (BP.pkl): Backpropagation-based sentiment classification model.
48
+ DNN (DP.keras): Deep Neural Network sentiment classification model.
49
+ RNN (RN.keras): Recurrent Neural Network sentiment classification model.
50
+ LSTM (LS.keras): Long Short-Term Memory sentiment classification model.
51
+ CNN (CN.keras): Convolutional Neural Network tumor detection model.
52
+
53
+ Contributing
54
+
55
+ Feel free to contribute by opening issues or submitting pull requests. Please follow the contribution guidelines.
56
+ License
57
+
58
+ This project is licensed under the MIT License - see the LICENSE file for details.
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,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
34
+ # Choose between tasks
35
+ task = st.radio("Select Task", ("Sentiment Classification", "Tumor Detection"))
36
+
37
+ if task == "Sentiment Classification":
38
+ # Input box for new review
39
+ new_review_text = st.text_area("Enter a New Review:", value="")
40
+ if st.button("Submit") and not new_review_text.strip():
41
+ st.warning("Please enter a review.")
42
+
43
+ if new_review_text.strip():
44
+ st.subheader("Choose Model for Sentiment Classification")
45
+ model_option = st.selectbox("Select Model", ("Perceptron", "Backpropagation", "DNN", "RNN", "LSTM"))
46
+
47
+ # Load models dynamically based on the selected option
48
+ if model_option == "Perceptron":
49
+ with open('PP.pkl', 'rb') as file:
50
+ model = pickle.load(file)
51
+ elif model_option == "Backpropagation":
52
+ with open('BP.pkl', 'rb') as file:
53
+ model = pickle.load(file)
54
+ elif model_option == "DNN":
55
+ model = load_model('DP.keras')
56
+ elif model_option == "RNN":
57
+ model = load_model('RN.keras')
58
+ elif model_option == "LSTM":
59
+ model = load_model('LS.keras')
60
+
61
+ if st.button("Classify Sentiment"):
62
+ result = sentiment_classification(new_review_text, model)
63
+ st.subheader("Sentiment Classification Result")
64
+ st.write(f"**{result}**")
65
+
66
+ elif task == "Tumor Detection":
67
+ st.subheader("Tumor Detection")
68
+ uploaded_file = st.file_uploader("Choose a tumor image...", type=["jpg", "jpeg", "png"])
69
+
70
+ if uploaded_file is not None:
71
+ # Load the tumor detection model
72
+ model = load_model('CN.keras')
73
+ st.image(uploaded_file, caption="Uploaded Image.", use_column_width=False, width=200)
74
+ st.write("")
75
+
76
+ if st.button("Detect Tumor"):
77
+ result = tumor_detection(uploaded_file, model)
78
+ st.subheader("Tumor Detection Result")
79
+ st.write(f"**{result}**")
Streamlit_url.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ https://deep-prediction-app.streamlit.app/
main.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import cv2
3
+ from tensorflow.keras.models import load_model
4
+ from tensorflow.keras.datasets import imdb
5
+ from PIL import Image
6
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
7
+ import pickle
8
+
9
+ with open('PP.pkl', 'rb') as file:
10
+ PP = pickle.load(file)
11
+ with open('BP.pkl', 'rb') as file:
12
+ BP = pickle.load(file)
13
+
14
+ LS = load_model('LS.keras')
15
+ DP = load_model('DP.keras')
16
+ CN = load_model('CN.keras')
17
+ RN = load_model('RN.keras')
18
+
19
+ new_review_text = "songs are of and and is morality it's her or know would care i i br screen that obvious plot actors new would with paris not have attempt lead or of too would local that of every their it coming this and of information to and br and movie was and that film is under by left this and is entertainment ok this in own be house of sticks worker in bound my i i obviously sake things just as lost lot br comes never like thing start of obviously comes indeed coming want no bad than history from lost comes accidentally young to movie bad facts dream from reason these honor movie elizabeth it's movie so fi and enough to computer duo film and almost jeffrey rarely obviously and alive to appears i i only human it and just only hop to be hop new made comes evidence blues high in want to other blues of their for and those i'm and that and obviously message obviously obviously for and of and brother br and make and lit and this and of blood br andy worst and it and this across as it when lines that make excellent scenery that there is julia fantasy to and and film good br of loose and basic have into your whatever i i and and demented be hop this standards cole new be home all seek film wives lot br made and in at this of search how concept in thirty some this and not all it rachel are of boys and re is and animals deserve i i worst more it is renting concerned message made all and in does of nor of nor side be and center obviously know end computer here to all tries in does of nor side of home br be indeed i i all it officer in could is performance and fully in of and br by br and its and lit well of nor at coming it's it that an this obviously i i this as their has obviously bad and exist countless and mixed of and br work to of run up and and br dear nor this early her bad having tortured film and movie all care of their br be right acting i i and of and and it away of its shooting and to suffering version you br and your way just and was can't compared condition film of and br united obviously are up obviously not other just and was and as true was least of and certainly lady poorly of setting produced and br and to make just have 2 which and of and dialog and br of and say in can is you for it wasn't in and as by it away plenty what have reason and are that willing that's have 2 which sister and of important br halfway to of took work 20 br similar more he good and for hit at coming not see reputation "
20
+
21
+ max_review_length = 500
22
+
23
+ word_to_index = imdb.get_word_index()
24
+ new_review_tokens = [word_to_index.get(word, 0) for word in new_review_text.split()]
25
+ new_review_tokens = pad_sequences([new_review_tokens], maxlen=max_review_length)
26
+
27
+ # Make the prediction
28
+ prediction = PP.predict(new_review_tokens)
29
+
30
+ print(prediction)
31
+
32
+ if prediction>0.3:
33
+ print('Positive')
34
+ else:
35
+ print("Negative")
36
+
37
+ def make_prediction(img,model):
38
+ img=cv2.imread(img)
39
+ img=Image.fromarray(img)
40
+ img=img.resize((128,128))
41
+ img=np.array(img)
42
+ input_img = np.expand_dims(img, axis=0)
43
+ res = model.predict(input_img)
44
+ if res:
45
+ print("Tumor Detected")
46
+ else:
47
+ print("No Tumor")
48
+
49
+ #make_prediction(r'C:\Users\shahi\Desktop\My Projects\DeepPredictorHub\CNN\tumordata\pred\pred3.jpg',CN)
50
+
51
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ numpy
3
+ Pillow
4
+ tensorflow
5
+ tqdm