monsifnadir commited on
Commit
2d985e0
·
verified ·
1 Parent(s): ff898c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -2
app.py CHANGED
@@ -1,2 +1,37 @@
1
-
2
- (COPY AND PASTE YOUR SCRIPT HERE)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the sentiment analysis pipeline
5
+ model_name = "monsifnadir/DarijaBERT-Sentiment" # Remplacez par le bon modèle si nécessaire
6
+ sentiment_pipeline = pipeline("text-classification", model=model_name)
7
+
8
+ # Mapping des labels Hugging Face vers des catégories de sentiments compréhensibles
9
+ label_map = {
10
+ "LABEL_0": "Negative",
11
+ "LABEL_1": "Neutral",
12
+ "LABEL_2": "Positive"
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
+ # Convertir le label en catégorie de sentiment
22
+ sentiment = label_map.get(label, "Unknown")
23
+ return f"Sentiment: {sentiment} (Confidence: {score:.2f})"
24
+
25
+ # Interface Gradio
26
+ iface = gr.Interface(
27
+ fn=classify_text,
28
+ inputs=gr.Textbox(lines=2, placeholder="Enter a Darija sentence..."),
29
+ outputs="text",
30
+ title="Darija Sentiment Analysis",
31
+ description="Enter a text in Darija to analyze its sentiment (Positive, Negative, Neutral)."
32
+ )
33
+
34
+ # Lancer l’application
35
+ iface.launch()
36
+
37
+