13nishit commited on
Commit
121aee2
·
verified ·
1 Parent(s): 79663d5

Delete main.py

Browse files
Files changed (1) hide show
  1. main.py +0 -73
main.py DELETED
@@ -1,73 +0,0 @@
1
- from flask import Flask, render_template, request
2
- import pickle
3
- import string
4
- import nltk
5
- from nltk.corpus import stopwords
6
- from nltk.stem.porter import PorterStemmer
7
-
8
- app = Flask(__name__)
9
-
10
- # Downloading NLTK libraries
11
- nltk.download('punkt')
12
- nltk.download('stopwords')
13
-
14
- ps = PorterStemmer()
15
-
16
- def transform_text(text):
17
- text = text.lower()
18
- text = nltk.word_tokenize(text)
19
- y = []
20
- for i in text:
21
- if i.isalnum():
22
- y.append(i)
23
-
24
- text = y[:]
25
- y.clear()
26
-
27
- for i in text:
28
- if i not in stopwords.words('english') and i not in string.punctuation:
29
- y.append(i)
30
-
31
- text = y[:]
32
- y.clear()
33
-
34
- for i in text:
35
- y.append(ps.stem(i))
36
-
37
- return " ".join(y)
38
-
39
- # Load the TF-IDF vectorizer and the model
40
- with open('vectorizer.pkl', 'rb') as f:
41
- tfidf = pickle.load(f)
42
-
43
- with open('model.pkl', 'rb') as f:
44
- model = pickle.load(f)
45
-
46
- @app.route('/')
47
- def index():
48
- return render_template('index.html')
49
-
50
- @app.route('/predict', methods=['POST'])
51
- def predict():
52
- if request.method == 'POST':
53
- input_sms = request.form['sms']
54
-
55
- # Preprocess the input
56
- transform_sms = transform_text(input_sms)
57
-
58
- # Vectorize the input
59
- vector_input = tfidf.transform([transform_sms])
60
-
61
- # Predict
62
- result = model.predict(vector_input)[0]
63
- # Convert result to string
64
- if result == 1:
65
- result_text = "SPAM"
66
- else:
67
- result_text = "NOT SPAM"
68
-
69
- # Return prediction result
70
- return render_template('result.html', result=result_text)
71
-
72
- if __name__ == '__main__':
73
- app.run(debug=True)