Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import joblib | |
| # Load model and vectorizer | |
| model = joblib.load("sentiment_model.pkl") | |
| tfidf = joblib.load("tfidf_vectorizer.pkl") | |
| def predict_sentiment(text): | |
| if not text.strip(): | |
| return "Please enter some text." | |
| # Transform the text using the same TF-IDF vectorizer | |
| vector = tfidf.transform([text]) | |
| # Predict sentiment | |
| prediction = model.predict(vector)[0] | |
| # Optional: make prediction readable | |
| if prediction == 1: | |
| label = "π Positive" | |
| elif prediction == 0 : | |
| label = "π Negative" | |
| return label | |
| # Gradio Interface | |
| iface = gr.Interface( | |
| fn=predict_sentiment, | |
| inputs=gr.Textbox(lines=2, placeholder="Enter text here..."), | |
| outputs="text", | |
| title="Sentiment Classifier", | |
| description="Predicts whether a sentence is positive, neutral, or negative using an XGBoost model." | |
| ) | |
| iface.launch() | |