-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
189 lines (143 loc) · 5.52 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# -*- coding: utf-8 -*-
"""App.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1bOfm14xqvozpu8yMO6MUskaPxksFskzu
"""
# !pip install streamlit
import streamlit as st
import pandas as pd
import pickle
import string
import nltk
nltk.download('punkt')
nltk.download('stopwords')
from nltk.corpus import stopwords
from nltk.stem.porter import PorterStemmer
with open('model.pkl', 'rb') as file:
loaded_model = pickle.load(file)
# with open('stand.pkl', 'rb') as scaler_file:
# scaler_iris = pickle.load(scaler_file)
with open('model2.pkl', 'rb') as file:
loaded_model = pickle.load(file)
# with open('minmax.pkl', 'rb') as scaler_file2:
# scaler2 = pickle.load(scaler_file2)
html_temp_title = """
<div style="background-color:#ff0000;padding:10px;margin-bottom:20px">
<h1 style="color:white;text-align:center;">OIBSIP Internship</h1>
</div>
"""
st.markdown(html_temp_title, unsafe_allow_html=True)
html_attribution = """
<div style="background-color:#28a745;padding:20px;margin-bottom:20px">
<p style="color:white;text-align:center;font-size:22px;">Developed by ANISHA V S</p>
</div>
"""
st.markdown(html_attribution, unsafe_allow_html=True)
col1, col2, col3 = st.columns(3)
with col1:
if st.button('Iris Classification'):
st.experimental_set_query_params(project="iris")
with col2:
if st.button('Sales Prediction'):
st.experimental_set_query_params(project="sales")
with col3:
if st.button('SPAM Detection'):
st.experimental_set_query_params(project="spam")
query_params = st.experimental_get_query_params()
project = query_params.get("project", ["iris"])[0]
if project == "iris":
html_temp_subtitle = """
<div style="background-color:#007bff;padding:10px;margin-bottom:20px">
<h2 style="color:white;text-align:center;">Iris Flower Prediction</h2>
</div>
"""
st.markdown(html_temp_subtitle, unsafe_allow_html=True)
def user_input_features():
sepal_length = st.number_input('Sepal length', 4.3, 7.9, 5.4)
sepal_width = st.number_input('Sepal width', 2.0, 4.4, 3.4)
petal_length = st.number_input('Petal length', 1.0, 6.9, 1.3)
petal_width = st.number_input('Petal width', 0.1, 2.5, 0.2)
data = {'SepalLengthCm': sepal_length,
'SepalWidthCm': sepal_width,
'PetalLengthCm': petal_length,
'PetalWidthCm': petal_width}
features = pd.DataFrame(data, index=[0])
return features
st.subheader('Enter Input ')
df = user_input_features()
st.subheader(' Input parameters')
st.write(df)
expected_features = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']
df = df[expected_features]
if st.button('Predict'):
scaled_features = scaler_iris.transform(df)
prediction = clf_iris.predict(scaled_features)
species = ['Iris-setosa', 'Iris-versicolor', 'Iris-virginica']
predicted_species = species[prediction[0]]
st.subheader('Prediction')
st.write(f"The predicted Iris species is: **{predicted_species}**")
elif project == "sales":
html_temp_subtitle = """
<div style="background-color:#007bff;padding:10px;margin-bottom:20px">
<h2 style="color:white;text-align:center;">Sales Prediction</h2>
</div>
"""
st.markdown(html_temp_subtitle, unsafe_allow_html=True)
def user_input_features():
i1 = st.number_input('TV')
i2 = st.number_input('Radio')
i3 = st.number_input('Newspaper')
data = {'TV': i1, 'Radio': i2, 'Newspaper': i3}
features = pd.DataFrame(data, index=[0])
return features
st.subheader('Enter Input ')
df = user_input_features()
st.subheader('Input parameters')
st.write(df)
expected_features = ['TV', 'Radio', 'Newspaper']
df = df[expected_features]
if st.button('Predict'):
scaled_features = scaler2.transform(df)
prediction = xgb.predict(scaled_features)
predicted_sales = prediction[0]
st.subheader('Prediction')
st.write(f"The predicted sales amount is: **{predicted_sales}**")
# elif project == "spam":
# html_temp_subtitle = """
# <div style="background-color:#ff6347;padding:10px;margin-bottom:20px">
# <h2 style="color:white;text-align:center;">SPAM Detection</h2>
# </div>
# """
# st.markdown(html_temp_subtitle, unsafe_allow_html=True)
# st.subheader('Enter Text')
# ps = PorterStemmer()
# def transform_text(text):
# text = text.lower()
# text = nltk.word_tokenize(text)
# y = []
# for i in text:
# if i.isalnum():
# y.append(i)
# text = y[:]
# y.clear()
# for i in text:
# if i not in stopwords.words('english') and i not in string.punctuation:
# y.append(i)
# text = y[:]
# y.clear()
# for i in text:
# y.append(ps.stem(i))
# return " ".join(y)
# tfidf = pickle.load(open('vectorizer2.pkl','rb'))
# model = pickle.load(open('model3b.pkl','rb'))
# st.title("SMS Spam Classifier")
# input_sms = st.text_area("Enter the message")
# if st.button('Predict'):
# # transformed_sms = transform_text(input_sms)
# vector_input = tfidf.transform([input_sms])
# result = model.predict(vector_input)[0]
# if result == 1:
# st.header("Spam")
# elif result==0:
# st.header("Not Spam")