Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# Load the sentiment analysis pipeline
|
5 |
-
model_name = "monsifnadir/DarijaBERT-Sentiment" #
|
6 |
sentiment_pipeline = pipeline("text-classification", model=model_name)
|
7 |
|
8 |
-
#
|
9 |
label_map = {
|
10 |
"LABEL_0": "Negative",
|
11 |
"LABEL_1": "Neutral",
|
@@ -13,16 +13,15 @@ label_map = {
|
|
13 |
}
|
14 |
|
15 |
def classify_text(text):
|
16 |
-
"""Analyse le sentiment du texte."""
|
17 |
result = sentiment_pipeline(text)
|
18 |
label = result[0]["label"]
|
19 |
score = result[0]["score"]
|
20 |
|
21 |
-
#
|
22 |
sentiment = label_map.get(label, "Unknown")
|
23 |
return f"Sentiment: {sentiment} (Confidence: {score:.2f})"
|
24 |
|
25 |
-
#
|
26 |
iface = gr.Interface(
|
27 |
fn=classify_text,
|
28 |
inputs=gr.Textbox(lines=2, placeholder="Enter a Darija sentence..."),
|
@@ -31,7 +30,8 @@ iface = gr.Interface(
|
|
31 |
description="Enter a text in Darija to analyze its sentiment (Positive, Negative, Neutral)."
|
32 |
)
|
33 |
|
34 |
-
#
|
35 |
iface.launch()
|
36 |
|
37 |
|
|
|
|
1 |
+
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# Load the sentiment analysis pipeline
|
5 |
+
model_name = "monsifnadir/DarijaBERT-Sentiment" # Change if necessary
|
6 |
sentiment_pipeline = pipeline("text-classification", model=model_name)
|
7 |
|
8 |
+
# Map numerical labels to sentiment categories
|
9 |
label_map = {
|
10 |
"LABEL_0": "Negative",
|
11 |
"LABEL_1": "Neutral",
|
|
|
13 |
}
|
14 |
|
15 |
def classify_text(text):
|
|
|
16 |
result = sentiment_pipeline(text)
|
17 |
label = result[0]["label"]
|
18 |
score = result[0]["score"]
|
19 |
|
20 |
+
# Map the label to actual sentiment
|
21 |
sentiment = label_map.get(label, "Unknown")
|
22 |
return f"Sentiment: {sentiment} (Confidence: {score:.2f})"
|
23 |
|
24 |
+
# Create Gradio interface
|
25 |
iface = gr.Interface(
|
26 |
fn=classify_text,
|
27 |
inputs=gr.Textbox(lines=2, placeholder="Enter a Darija sentence..."),
|
|
|
30 |
description="Enter a text in Darija to analyze its sentiment (Positive, Negative, Neutral)."
|
31 |
)
|
32 |
|
33 |
+
# Launch the app
|
34 |
iface.launch()
|
35 |
|
36 |
|
37 |
+
|