Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- Readme.md +16 -0
- Requirements.txt +5 -0
- app.py +37 -0
- sentiment_model.pkl +3 -0
- tfidf_vectorizer.pkl +3 -0
Readme.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ๐ Sentiment Analysis with Gradio
|
| 2 |
+
|
| 3 |
+
This project demonstrates **Sentiment Analysis** using a dataset of social media posts.
|
| 4 |
+
The goal is to classify text into **Positive, Negative, or Neutral** sentiments using Natural Language Processing (NLP) techniques and deploy the model with a **Gradio interactive web app**.
|
| 5 |
+
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
## ๐ Features
|
| 9 |
+
- Text preprocessing (cleaning, tokenization, stopword removal)
|
| 10 |
+
- Sentiment classification using **TF-IDF + Logistic Regression**
|
| 11 |
+
- Interactive **Gradio app** for real-time predictions
|
| 12 |
+
- Easy deployment and sharing via Colab or GitHub
|
| 13 |
+
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
## ๐ Project Structure
|
Requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas
|
| 2 |
+
scikit-learn
|
| 3 |
+
nltk
|
| 4 |
+
gradio
|
| 5 |
+
joblib
|
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import joblib
|
| 4 |
+
import re
|
| 5 |
+
import nltk
|
| 6 |
+
from nltk.corpus import stopwords
|
| 7 |
+
from nltk.tokenize import word_tokenize
|
| 8 |
+
|
| 9 |
+
# Load saved model and vectorizer
|
| 10 |
+
model = joblib.load("sentiment_model.pkl")
|
| 11 |
+
vectorizer = joblib.load("tfidf_vectorizer.pkl")
|
| 12 |
+
|
| 13 |
+
nltk.download('punkt')
|
| 14 |
+
nltk.download('stopwords')
|
| 15 |
+
|
| 16 |
+
def preprocess(text):
|
| 17 |
+
text = str(text).lower()
|
| 18 |
+
text = re.sub(r'[^a-z\s]', '', text)
|
| 19 |
+
tokens = word_tokenize(text)
|
| 20 |
+
tokens = [t for t in tokens if t not in stopwords.words('english')]
|
| 21 |
+
return ' '.join(tokens)
|
| 22 |
+
|
| 23 |
+
def predict_sentiment(text):
|
| 24 |
+
processed = preprocess(text)
|
| 25 |
+
vectorized = vectorizer.transform([processed])
|
| 26 |
+
prediction = model.predict(vectorized)[0]
|
| 27 |
+
return prediction
|
| 28 |
+
|
| 29 |
+
demo = gr.Interface(
|
| 30 |
+
fn=predict_sentiment,
|
| 31 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
| 32 |
+
outputs="label",
|
| 33 |
+
title="Sentiment Analysis App",
|
| 34 |
+
description="Classify text as Positive, Negative, or Neutral"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
demo.launch()
|
sentiment_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8993f3518cb64af77edc4170dfc9c1cd8d54dcaafa7cbe6b243fd38ca8175967
|
| 3 |
+
size 31711
|
tfidf_vectorizer.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ce96ea918674ec6ed82d2896219515ff4bd0649a6f1772f914fe8066160bb292
|
| 3 |
+
size 25819
|