Spaces:
Sleeping
Sleeping
File size: 934 Bytes
1ca8529 e7f80c6 1ca8529 e7f80c6 1ca8529 e7f80c6 1ca8529 e7f80c6 d7d5ded fee9937 e7f80c6 d7d5ded e7f80c6 1ca8529 e7f80c6 1ca8529 e7f80c6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
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()
|