Spaces:
Running
Running
Created new prediction function.
Browse files
app.py
CHANGED
@@ -11,10 +11,10 @@ from sklearn.feature_extraction.text import CountVectorizer
|
|
11 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
12 |
|
13 |
# file name
|
14 |
-
lr_filename = 'lr_021223.pkl'
|
15 |
|
16 |
# Load model from pickle file
|
17 |
-
model = pickle.load(open(lr_filename, 'rb'))
|
18 |
|
19 |
|
20 |
# Process input text, including removing stopwords, converting to lowercase, and removing punctuation
|
@@ -29,21 +29,31 @@ def process_text(text):
|
|
29 |
return text
|
30 |
|
31 |
# Vectorize input text
|
32 |
-
|
|
|
33 |
def vectorize_text(text):
|
34 |
-
text = process_text(text)
|
35 |
-
text = vectorizer.fit_transform([text])
|
36 |
-
return text
|
|
|
37 |
|
38 |
# Valid input for the model so number of features match
|
39 |
-
# Code will go here
|
40 |
-
|
41 |
-
# Prediction function
|
42 |
def predict(text):
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
45 |
return prediction
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
# Define interface
|
49 |
demo = gr.Interface(fn=predict,
|
|
|
11 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
12 |
|
13 |
# file name
|
14 |
+
#lr_filename = 'lr_021223.pkl'
|
15 |
|
16 |
# Load model from pickle file
|
17 |
+
# model = pickle.load(open(lr_filename, 'rb'))
|
18 |
|
19 |
|
20 |
# Process input text, including removing stopwords, converting to lowercase, and removing punctuation
|
|
|
29 |
return text
|
30 |
|
31 |
# Vectorize input text
|
32 |
+
vec = CountVectorizer()
|
33 |
+
'''
|
34 |
def vectorize_text(text):
|
35 |
+
#text = process_text(text)
|
36 |
+
#text = vectorizer.fit_transform([text])
|
37 |
+
#return text
|
38 |
+
'''
|
39 |
|
40 |
# Valid input for the model so number of features match
|
|
|
|
|
|
|
41 |
def predict(text):
|
42 |
+
# Load the pickled model
|
43 |
+
filename = 'lr_021223.pkl'
|
44 |
+
loaded_model = pickle.load(open(filename, 'rb'))
|
45 |
+
text = process_text(text)
|
46 |
+
text = vec.transform([text])
|
47 |
+
prediction = loaded_model.predict(text)
|
48 |
return prediction
|
49 |
|
50 |
+
'''
|
51 |
+
Prediction function
|
52 |
+
#def predict(text):
|
53 |
+
#text = vectorize_text(text)
|
54 |
+
#prediction = model.predict(text)
|
55 |
+
#return prediction
|
56 |
+
'''
|
57 |
|
58 |
# Define interface
|
59 |
demo = gr.Interface(fn=predict,
|