Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,38 +3,49 @@ import numpy as np
|
|
| 3 |
import pickle
|
| 4 |
import streamlit.components.v1 as components
|
| 5 |
from sklearn.feature_extraction.text import CountVectorizer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
# Load the pickled model
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Function for model prediction
|
| 12 |
-
def model_prediction(
|
| 13 |
-
features =
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def app_design():
|
| 18 |
# Add input fields for High, Open, and Low values
|
| 19 |
-
image = '
|
| 20 |
-
st.image(image, use_column_width=True)
|
| 21 |
|
| 22 |
st.subheader("Enter the following values:")
|
| 23 |
|
| 24 |
text= st.text_input("Enter your message")
|
| 25 |
# Create a feature list from the user inputs
|
| 26 |
-
features =
|
| 27 |
-
|
| 28 |
-
# Load the model
|
| 29 |
-
model = load_model()
|
| 30 |
|
| 31 |
# Make a prediction when the user clicks the "Predict" button
|
| 32 |
if st.button('Predict Sarcasm'):
|
| 33 |
-
predicted_value = model_prediction(
|
| 34 |
-
if predicted_value == 'Sarcasm':
|
| 35 |
-
st.success(
|
| 36 |
-
|
| 37 |
-
st.success(
|
| 38 |
|
| 39 |
|
| 40 |
|
|
|
|
| 3 |
import pickle
|
| 4 |
import streamlit.components.v1 as components
|
| 5 |
from sklearn.feature_extraction.text import CountVectorizer
|
| 6 |
+
from sklearn.model_selection import train_test_split
|
| 7 |
+
import pandas as pd
|
| 8 |
+
# Separate target and feature column in X and y variable
|
| 9 |
+
df = pd.read_json('sarcasm.json',lines = True)
|
| 10 |
+
# X will be the features
|
| 11 |
+
X = np.array(df["headline"])
|
| 12 |
|
| 13 |
+
# y will be the target variable
|
| 14 |
+
y = np.array(df["is_sarcastic"])
|
| 15 |
+
cv = CountVectorizer()
|
| 16 |
# Load the pickled model
|
| 17 |
+
|
| 18 |
+
X = cv.fit_transform(X)
|
| 19 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y,
|
| 20 |
+
test_size=0.33,
|
| 21 |
+
random_state=42)
|
| 22 |
|
| 23 |
# Function for model prediction
|
| 24 |
+
def model_prediction(features):
|
| 25 |
+
features = cv.transform([features]).toarray()
|
| 26 |
+
pickled_model = pickle.load(open('Sarcasm_Detection_BernoulliNB.pkl', 'rb'))
|
| 27 |
+
Message = str(list(pickled_model.predict(features)))
|
| 28 |
+
|
| 29 |
+
return Message
|
| 30 |
|
| 31 |
def app_design():
|
| 32 |
# Add input fields for High, Open, and Low values
|
| 33 |
+
# image = '21.png' # Load image
|
| 34 |
+
# st.image(image, use_column_width=True)
|
| 35 |
|
| 36 |
st.subheader("Enter the following values:")
|
| 37 |
|
| 38 |
text= st.text_input("Enter your message")
|
| 39 |
# Create a feature list from the user inputs
|
| 40 |
+
features = text # add features according to notebook
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# Make a prediction when the user clicks the "Predict" button
|
| 43 |
if st.button('Predict Sarcasm'):
|
| 44 |
+
predicted_value = model_prediction(features)
|
| 45 |
+
if predicted_value == "['Sarcasm']":
|
| 46 |
+
st.success("Your message contains Sarcasm")
|
| 47 |
+
elif predicted_value == "['Not Sarcasm']":
|
| 48 |
+
st.success("Your message doesnot contains Sarcasm")
|
| 49 |
|
| 50 |
|
| 51 |
|