ibrahimnomad commited on
Commit
fb405cf
1 Parent(s): 54b8369

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +42 -0
  2. machine.png +0 -0
  3. requirements.txt +3 -0
  4. sarcasm.json +0 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import json
3
+ import numpy as np
4
+ from sklearn.feature_extraction.text import CountVectorizer
5
+ from sklearn.model_selection import train_test_split
6
+ from sklearn.naive_bayes import BernoulliNB
7
+ import streamlit as st
8
+
9
+ # Load the dataset
10
+ df = pd.read_json('sarcasm.json', lines=True)
11
+ df = df[["headline", "is_sarcastic"]]
12
+ df["is_sarcastic"] = df["is_sarcastic"].map({0: "Serious", 1: "Sarcastic/Lie"})
13
+
14
+ # Train the model
15
+ x = np.array(df["headline"])
16
+ y = np.array(df["is_sarcastic"])
17
+ cv = CountVectorizer()
18
+ X = cv.fit_transform(x)
19
+ x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=42)
20
+ model = BernoulliNB()
21
+ model.fit(x_train, y_train)
22
+
23
+ # Define Streamlit app
24
+ def main():
25
+ st.title('Sarcasm & Lie Detector :clown_face:')
26
+ st.write('Autism Special Edition')
27
+ st.image('machine.png')
28
+ # Input field for user to enter text
29
+ user_input = st.text_input("Enter text:", "Dogs can fly now")
30
+
31
+ if st.button("Check"):
32
+ # Make prediction
33
+ data = cv.transform([user_input]).toarray()
34
+ prediction = model.predict(data)
35
+
36
+ # Display prediction result
37
+ st.write("This is ", prediction[0])
38
+
39
+ st.write('Reference dataframe')
40
+ st.dataframe(df.head(300))
41
+ if __name__ == '__main__':
42
+ main()
machine.png ADDED
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pandas
2
+ scikit-learn
3
+ streamlit
sarcasm.json ADDED
The diff for this file is too large to render. See raw diff