DineshKumar1329 commited on
Commit
de1c173
1 Parent(s): 619f18c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +32 -1
README.md CHANGED
@@ -21,5 +21,36 @@ The sentiment analysis model is trained using a Support Vector Machine (SVM) cla
21
 
22
  # Usage :
23
 
24
- ![image/png](https://cdn-uploads.huggingface.co/production/uploads/65dd9dc387458446d0a9da32/MlAfwDkAouKP5iWtzqHPj.png)
 
 
 
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  # Usage :
23
 
24
+ ```python
25
+ from huggingface_hub import hf_hub_download
26
+ import joblib
27
+ from sklearn.preprocessing import LabelEncoder
28
 
29
+ # Download and load the sentiment analysis model from Hugging Face Model Hub
30
+ model = joblib.load(hf_hub_download("DineshKumar1329/Sentiment_Analysis", "sklearn_model.joblib"))
31
+
32
+ # Load the TF-IDF vectorizer
33
+ tfidf_vectorizer = joblib.load(hf_hub_download("DineshKumar1329/Sentiment_Analysis", "vectorizer_model.joblib"))
34
+
35
+ def clean_text(text):
36
+ return text.lower()
37
+
38
+ def predict_sentiment(user_input):
39
+ """Predicts sentiment for a given user input."""
40
+ cleaned_text = clean_text(user_input)
41
+ input_matrix = tfidf_vectorizer.transform([cleaned_text])
42
+ prediction = model.predict(input_matrix)[0]
43
+
44
+ if isinstance(model.classes_, LabelEncoder):
45
+ prediction = model.classes_.inverse_transform([prediction])[0]
46
+
47
+ return prediction
48
+
49
+ # Get user input
50
+ user_input = input("Enter a sentence: ")
51
+
52
+ # Predict sentiment
53
+ predicted_sentiment = predict_sentiment(user_input)
54
+
55
+ # Output the prediction
56
+ print(f"Predicted Sentiment: {predicted_sentiment}")