Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
from sklearn.naive_bayes import MultinomialNB
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
("I love this movie!", "positive"),
|
8 |
-
("This is terrible.", "negative"),
|
9 |
-
("What a great experience!", "positive"),
|
10 |
-
("I hate waiting in line.", "negative"),
|
11 |
-
("The weather is nice today.", "positive"),
|
12 |
-
("I'm so disappointed.", "negative"),
|
13 |
-
("It was okay, not great.", "negative"),
|
14 |
-
("Fantastic service!", "positive"),
|
15 |
-
("Worst day ever.", "negative"),
|
16 |
-
("Such a beautiful moment.", "positive"),
|
17 |
-
]
|
18 |
|
19 |
-
X = [sentence for sentence, label in data]
|
20 |
-
y = [label for sentence, label in data]
|
21 |
-
|
22 |
-
vectorizer = TfidfVectorizer()
|
23 |
-
X_vectorized = vectorizer.fit_transform(X)
|
24 |
-
|
25 |
-
model = MultinomialNB()
|
26 |
-
model.fit(X_vectorized, y)
|
27 |
-
|
28 |
-
# Prediction function
|
29 |
def predict_sentiment(text):
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
33 |
return "β
POSITIVE π"
|
34 |
else:
|
35 |
return "β NEGATIVE π "
|
@@ -40,10 +19,9 @@ demo = gr.Interface(
|
|
40 |
inputs=gr.Textbox(lines=3, placeholder="Type your sentence here..."),
|
41 |
outputs="text",
|
42 |
title="π¬ LM Studios Sentiment Detector",
|
43 |
-
description="
|
44 |
theme="default",
|
45 |
-
flagging_mode="never"
|
46 |
-
live=False
|
47 |
)
|
48 |
|
49 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
|
|
3 |
|
4 |
+
# Load the pretrained sentiment pipeline
|
5 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def predict_sentiment(text):
|
8 |
+
result = sentiment_pipeline(text)[0]
|
9 |
+
label = result["label"]
|
10 |
+
|
11 |
+
if label == "POSITIVE":
|
12 |
return "β
POSITIVE π"
|
13 |
else:
|
14 |
return "β NEGATIVE π "
|
|
|
19 |
inputs=gr.Textbox(lines=3, placeholder="Type your sentence here..."),
|
20 |
outputs="text",
|
21 |
title="π¬ LM Studios Sentiment Detector",
|
22 |
+
description="Now powered by a Hugging Face transformer model for smarter predictions.",
|
23 |
theme="default",
|
24 |
+
flagging_mode="never"
|
|
|
25 |
)
|
26 |
|
27 |
demo.launch()
|