problem
Browse files
app.py
CHANGED
@@ -3,12 +3,19 @@ from transformers import pipeline
|
|
3 |
import pandas as pd
|
4 |
|
5 |
# Load the Hugging Face pipeline
|
6 |
-
classifier = pipeline(
|
|
|
|
|
|
|
7 |
|
8 |
# Define the full list of possible emotions (based on the model output structure)
|
9 |
ALL_EMOTIONS = ["sadness", "joy", "love", "anger", "fear", "surprise"]
|
10 |
|
11 |
def classify_emotion(text):
|
|
|
|
|
|
|
|
|
12 |
# Make predictions using the Hugging Face pipeline
|
13 |
predictions = classifier(text)
|
14 |
|
@@ -42,11 +49,11 @@ gr.Interface(
|
|
42 |
),
|
43 |
outputs=[
|
44 |
gr.BarPlot(
|
45 |
-
x="Emotion", #
|
46 |
-
y="Score", #
|
47 |
label="Emotion Scores Bar Plot",
|
48 |
title="Emotion Probabilities",
|
49 |
-
color="#2563eb", #
|
50 |
height=400,
|
51 |
vertical=True
|
52 |
),
|
|
|
3 |
import pandas as pd
|
4 |
|
5 |
# Load the Hugging Face pipeline
|
6 |
+
classifier = pipeline(
|
7 |
+
"text-classification",
|
8 |
+
model="bhadresh-savani/distilbert-base-uncased-emotion"
|
9 |
+
)
|
10 |
|
11 |
# Define the full list of possible emotions (based on the model output structure)
|
12 |
ALL_EMOTIONS = ["sadness", "joy", "love", "anger", "fear", "surprise"]
|
13 |
|
14 |
def classify_emotion(text):
|
15 |
+
# Check if input text is valid
|
16 |
+
if not text or not text.strip():
|
17 |
+
raise ValueError("Input text cannot be empty.") # Raise an error for invalid input
|
18 |
+
|
19 |
# Make predictions using the Hugging Face pipeline
|
20 |
predictions = classifier(text)
|
21 |
|
|
|
49 |
),
|
50 |
outputs=[
|
51 |
gr.BarPlot(
|
52 |
+
x="Emotion", # Specify the x-axis column
|
53 |
+
y="Score", # Specify the y-axis column
|
54 |
label="Emotion Scores Bar Plot",
|
55 |
title="Emotion Probabilities",
|
56 |
+
color="#2563eb", # Set the bar color
|
57 |
height=400,
|
58 |
vertical=True
|
59 |
),
|