File size: 1,291 Bytes
fb405cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import json
import numpy as np
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import BernoulliNB
import streamlit as st

# Load the dataset
df = pd.read_json('sarcasm.json', lines=True)
df = df[["headline", "is_sarcastic"]]
df["is_sarcastic"] = df["is_sarcastic"].map({0: "Serious", 1: "Sarcastic/Lie"})

# Train the model
x = np.array(df["headline"])
y = np.array(df["is_sarcastic"])
cv = CountVectorizer()
X = cv.fit_transform(x)
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=42)
model = BernoulliNB()
model.fit(x_train, y_train)

# Define Streamlit app
def main():
    st.title('Sarcasm & Lie Detector :clown_face:')
    st.write('Autism Special Edition')
    st.image('machine.png')
    # Input field for user to enter text
    user_input = st.text_input("Enter text:", "Dogs can fly now")
    
    if st.button("Check"):
        # Make prediction
        data = cv.transform([user_input]).toarray()
        prediction = model.predict(data)
        
        # Display prediction result
        st.write("This is ", prediction[0])

    st.write('Reference dataframe')
    st.dataframe(df.head(300))
if __name__ == '__main__':
    main()