Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- app.py +34 -0
- requirements +2 -0
- sentiment_model.pkl +3 -0
- vectorizer.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
|
| 4 |
+
# Load model and vectorizer
|
| 5 |
+
model = joblib.load("model/sentiment_model.pkl")
|
| 6 |
+
vectorizer = joblib.load("model/vectorizer.pkl")
|
| 7 |
+
|
| 8 |
+
# Prediction function
|
| 9 |
+
def predict_sentiment(text):
|
| 10 |
+
text_vector = vectorizer.transform([text])
|
| 11 |
+
prediction = model.predict(text_vector)[0]
|
| 12 |
+
proba = model.predict_proba(text_vector)[0]
|
| 13 |
+
|
| 14 |
+
sentiment = "Positive" if prediction == 1 else "Negative"
|
| 15 |
+
return {
|
| 16 |
+
"Sentiment": sentiment,
|
| 17 |
+
"Positive Probability": round(proba[1], 2),
|
| 18 |
+
"Negative Probability": round(proba[0], 2),
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
# Gradio UI
|
| 22 |
+
iface = gr.Interface(
|
| 23 |
+
fn=predict_sentiment,
|
| 24 |
+
inputs=gr.Textbox(label="Enter your review or message"),
|
| 25 |
+
outputs=[
|
| 26 |
+
gr.Label(label="Sentiment"),
|
| 27 |
+
gr.Label(label="Positive Probability"),
|
| 28 |
+
gr.Label(label="Negative Probability"),
|
| 29 |
+
],
|
| 30 |
+
title="Sentiment Analysis",
|
| 31 |
+
description="Enter a sentence to check if it's Positive or Negative.",
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
iface.launch()
|
requirements
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
scikit-learn
|
sentiment_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:68e433dc0104aed9bfe940eb80f2c46aa5614121fe13329e4b69916e808b74ce
|
| 3 |
+
size 6814751
|
vectorizer.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:58fbe652ee254316b6d687d350d2b0d790ca79dd8001745ec269244fe589ef23
|
| 3 |
+
size 22042389
|