Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,37 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
import
|
| 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 |
-
result = detect_sarcasm(combined_text)
|
| 39 |
-
print("OCR Extracted Text:", ocr_text)
|
| 40 |
-
print("Typed Text:", typed_text)
|
| 41 |
-
print("Combined Text:", combined_text)
|
| 42 |
-
print("Sarcasm Detection Result:", result)
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
from sklearn.feature_extraction.text import CountVectorizer
|
| 4 |
+
from sklearn.model_selection import train_test_split
|
| 5 |
+
from sklearn.naive_bayes import BernoulliNB
|
| 6 |
+
import streamlit as st
|
| 7 |
+
|
| 8 |
+
# Load dataset
|
| 9 |
+
df = pd.read_json('sarcasm.json', lines=True)
|
| 10 |
+
df = df[["headline", "is_sarcastic"]]
|
| 11 |
+
|
| 12 |
+
# Prepare data
|
| 13 |
+
x = np.array(df["headline"])
|
| 14 |
+
y = np.array(df["is_sarcastic"]) # 0 = Not Sarcastic, 1 = Sarcastic
|
| 15 |
+
|
| 16 |
+
cv = CountVectorizer()
|
| 17 |
+
X = cv.fit_transform(x)
|
| 18 |
+
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=42)
|
| 19 |
+
|
| 20 |
+
# Train model
|
| 21 |
+
model = BernoulliNB()
|
| 22 |
+
model.fit(x_train, y_train)
|
| 23 |
+
|
| 24 |
+
# Streamlit app
|
| 25 |
+
def main():
|
| 26 |
+
st.title('Simple Sarcasm Detector')
|
| 27 |
+
|
| 28 |
+
user_input = st.text_input("Enter text to check if sarcastic:")
|
| 29 |
+
|
| 30 |
+
if st.button("Check"):
|
| 31 |
+
data = cv.transform([user_input]).toarray()
|
| 32 |
+
prediction = model.predict(data)[0]
|
| 33 |
+
label = "Sarcastic" if prediction == 1 else "Not Sarcastic"
|
| 34 |
+
st.write(f"The entered text is: **{label}**")
|
| 35 |
+
|
| 36 |
+
if __name__ == '__main__':
|
| 37 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|