Delete chck.py
Browse files
chck.py
DELETED
@@ -1,80 +0,0 @@
|
|
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.preprocessing.text import Tokenizer
|
6 |
-
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
7 |
-
from tensorflow.keras.applications.inception_v3 import preprocess_input
|
8 |
-
import tensorflow as tf
|
9 |
-
import joblib
|
10 |
-
|
11 |
-
# Load saved models
|
12 |
-
image_model = load_model('tumor_detection_model.h5')
|
13 |
-
dnn_model = load_model('sms_spam_detection_dnnmodel.h5')
|
14 |
-
rnn_model = load_model('spam_detection_rnn_model.h5')
|
15 |
-
perceptron_model = joblib.load('imdb_perceptron_model.pkl')
|
16 |
-
backprop_model = joblib.load('backprop_model.pkl')
|
17 |
-
LSTM_model = load_model('imdb_LSTM.h5')
|
18 |
-
|
19 |
-
# Streamlit app
|
20 |
-
st.title("Classification")
|
21 |
-
|
22 |
-
# Sidebar
|
23 |
-
task = st.sidebar.selectbox("Select Task", ["Tumor Detection", "Sentiment Classification"])
|
24 |
-
|
25 |
-
def preprocess_message_dnn(message, tokeniser, max_length):
|
26 |
-
encoded_message = tokeniser.texts_to_sequences([message])
|
27 |
-
padded_message = pad_sequences(encoded_message, maxlen=max_length, padding='post')
|
28 |
-
return padded_message
|
29 |
-
|
30 |
-
def predict_dnnspam(message, tokeniser, max_length):
|
31 |
-
processed_message = preprocess_message_dnn(message, tokeniser, max_length)
|
32 |
-
prediction = dnn_model.predict(processed_message)
|
33 |
-
return "Spam" if prediction >= 0.5 else "Ham"
|
34 |
-
|
35 |
-
# Other prediction functions for sentiment analysis can follow a similar pattern
|
36 |
-
|
37 |
-
# Function for CNN prediction
|
38 |
-
def preprocess_image(image):
|
39 |
-
image = image.resize((299, 299))
|
40 |
-
image_array = np.array(image)
|
41 |
-
preprocessed_image = preprocess_input(image_array)
|
42 |
-
return preprocessed_image
|
43 |
-
|
44 |
-
def make_prediction_cnn(image, model):
|
45 |
-
img = image.resize((128, 128))
|
46 |
-
img_array = np.array(img)
|
47 |
-
img_array = img_array.reshape((1, img_array.shape[0], img_array.shape[1], img_array.shape[2]))
|
48 |
-
preprocessed_image = preprocess_input(img_array)
|
49 |
-
prediction = model.predict(preprocessed_image)
|
50 |
-
return "Tumor Detected" if prediction > 0.5 else "No Tumor"
|
51 |
-
|
52 |
-
if task == "Sentiment Classification":
|
53 |
-
st.subheader("Choose Model")
|
54 |
-
model_choice = st.radio("Select Model", ["DNN", "RNN", "Perceptron", "Backpropagation", "LSTM"])
|
55 |
-
|
56 |
-
st.subheader("Text Input")
|
57 |
-
text_input = st.text_area("Enter Text")
|
58 |
-
|
59 |
-
if st.button("Predict"):
|
60 |
-
if model_choice == "DNN":
|
61 |
-
# You need to define tokeniser and max_length for DNN model
|
62 |
-
prediction_result = predict_dnnspam(text_input, tokeniser, max_length)
|
63 |
-
st.write(f"The message is classified as: {prediction_result}")
|
64 |
-
# Other model choices should call respective prediction functions similarly
|
65 |
-
|
66 |
-
else:
|
67 |
-
st.subheader("Choose Model")
|
68 |
-
model_choice = st.radio("Select Model", ["CNN"])
|
69 |
-
|
70 |
-
st.subheader("Image Input")
|
71 |
-
image_input = st.file_uploader("Choose an image...", type="jpg")
|
72 |
-
|
73 |
-
if image_input is not None:
|
74 |
-
image = Image.open(image_input)
|
75 |
-
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
76 |
-
|
77 |
-
if st.button("Predict"):
|
78 |
-
if model_choice == "CNN":
|
79 |
-
prediction_result = make_prediction_cnn(image, image_model)
|
80 |
-
st.write(prediction_result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|