Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,10 +5,17 @@ from transformers import pipeline
|
|
5 |
model_name = "Jr0hamza/sentiment-analysis-model"
|
6 |
sentiment_pipeline = pipeline("text-classification", model=model_name)
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
# Function to predict sentiment
|
9 |
def predict_sentiment(text):
|
10 |
-
result = sentiment_pipeline(text)
|
11 |
-
|
|
|
12 |
|
13 |
# Gradio Interface
|
14 |
interface = gr.Interface(
|
|
|
5 |
model_name = "Jr0hamza/sentiment-analysis-model"
|
6 |
sentiment_pipeline = pipeline("text-classification", model=model_name)
|
7 |
|
8 |
+
# Define custom label mapping
|
9 |
+
label_map = {
|
10 |
+
"LABEL_0": "negative",
|
11 |
+
"LABEL_1": "positive"
|
12 |
+
}
|
13 |
+
|
14 |
# Function to predict sentiment
|
15 |
def predict_sentiment(text):
|
16 |
+
result = sentiment_pipeline(text)[0]
|
17 |
+
label = label_map.get(result["label"], "unknown") # Convert label
|
18 |
+
return f"Sentiment: {label} (Confidence: {result['score']:.2f})"
|
19 |
|
20 |
# Gradio Interface
|
21 |
interface = gr.Interface(
|