Update README.md
Browse files
README.md
CHANGED
|
@@ -18,50 +18,3 @@ The sentiment analysis model is trained using a Support Vector Machine (SVM) cla
|
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
- from huggingface_hub import hf_hub_download
|
| 24 |
-
- import joblib
|
| 25 |
-
- from sklearn.preprocessing import LabelEncoder
|
| 26 |
-
|
| 27 |
-
# Download the sentiment analysis model
|
| 28 |
-
- model = joblib.load(
|
| 29 |
-
hf_hub_download("DineshKumar1329/Sentiment_Analysis", "sklearn_model.joblib")
|
| 30 |
-
)
|
| 31 |
-
|
| 32 |
-
# Load the TF-IDF vectorizer
|
| 33 |
-
tfidf_vectorizer = joblib.load('/content/vectorizer_model.joblib') # Replace with your path
|
| 34 |
-
|
| 35 |
-
def clean_text(text):
|
| 36 |
-
# Implement your text cleaning logic here (e.g., lowercase, remove punctuation, etc.)
|
| 37 |
-
# This example simply lowercases the text
|
| 38 |
-
return text.lower()
|
| 39 |
-
|
| 40 |
-
def predict_sentiment(user_input):
|
| 41 |
-
"""Predicts sentiment for a given user input."""
|
| 42 |
-
cleaned_text = clean_text(user_input)
|
| 43 |
-
input_matrix = tfidf_vectorizer.transform([cleaned_text])
|
| 44 |
-
prediction = model.predict(input_matrix)[0]
|
| 45 |
-
|
| 46 |
-
if isinstance(model.classes_, LabelEncoder):
|
| 47 |
-
prediction = model.classes_.inverse_transform([prediction])[0]
|
| 48 |
-
|
| 49 |
-
return prediction
|
| 50 |
-
|
| 51 |
-
# Get user input
|
| 52 |
-
user_input = input("Enter a sentence: ")
|
| 53 |
-
|
| 54 |
-
# Predict sentiment
|
| 55 |
-
predicted_sentiment = predict_sentiment(user_input)
|
| 56 |
-
|
| 57 |
-
print(f"Predicted Sentiment: {predicted_sentiment}")
|
| 58 |
-
|
| 59 |
-
# Optional: Save predictions (modify paths as needed)
|
| 60 |
-
try:
|
| 61 |
-
df_existing = pd.read_excel('/content/output_predictions.xlsx')
|
| 62 |
-
except FileNotFoundError:
|
| 63 |
-
df_existing = pd.DataFrame()
|
| 64 |
-
|
| 65 |
-
new_prediction = pd.DataFrame({'User_Input': [user_input], 'Predicted_Sentiment': [predicted_sentiment]})
|
| 66 |
-
df_combined = pd.concat([df_existing, new_prediction], ignore_index=True)
|
| 67 |
-
df_combined.to_excel('/content/output_predictions.xlsx', index=False)
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|