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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -1,11 +1,11 @@
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",
@@ -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
- # 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..."),
@@ -31,7 +30,8 @@ iface = gr.Interface(
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
 
 
 
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
+