Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,36 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import pickle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
with open("sentiment_analysis_model.pkl", "rb") as file:
|
| 4 |
pipe2 = pickle.load(file)
|
| 5 |
def prediction(text):
|
|
|
|
|
|
|
| 1 |
import pickle
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
from sklearn.model_selection import train_test_split
|
| 7 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 8 |
+
from sklearn.preprocessing import LabelEncoder
|
| 9 |
+
from sklearn.pipeline import Pipeline
|
| 10 |
+
from sklearn.naive_bayes import MultinomialNB
|
| 11 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 12 |
+
from sklearn.metrics import accuracy_score, classification_report
|
| 13 |
+
|
| 14 |
+
import nltk
|
| 15 |
+
from nltk.tokenize import word_tokenize
|
| 16 |
+
from nltk.corpus import stopwords
|
| 17 |
+
from nltk.stem import WordNetLemmatizer
|
| 18 |
+
nltk.download('punkt')
|
| 19 |
+
nltk.download('stopwords')
|
| 20 |
+
nltk.download('wordnet')
|
| 21 |
+
def preprocess_nltk(text):
|
| 22 |
+
lemmatizer = WordNetLemmatizer()
|
| 23 |
+
tokens = word_tokenize(text.lower()) # Tokenization
|
| 24 |
+
stop_words = set(stopwords.words("english"))
|
| 25 |
+
filtered_tokens = [lemmatizer.lemmatize(token) for token in tokens if token.isalnum() and token not in stop_words]
|
| 26 |
+
return " ".join(filtered_tokens)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
with open("sentiment_analysis_model.pkl", "rb") as file:
|
| 35 |
pipe2 = pickle.load(file)
|
| 36 |
def prediction(text):
|