Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  from transformers import pipeline
3
 
4
  APP_NAME = "MoodMapper"
5
- MODEL_ID = "j-hartmann/emotion-english-distilroberta-base" # garde celui-ci pour l’instant
6
 
7
  _clf = None
8
  def get_clf():
@@ -17,18 +17,18 @@ def get_clf():
17
  return _clf
18
 
19
  EXAMPLES = [
20
- "I just got the internship — I'm so happy!",
21
- "Je suis déçue et un peu en colère par ce mail.",
22
- "This is fine, nothing special today.",
23
- "I'm worried about the deadline...",
24
- "Quelle surprise ! Je ne m’y attendais pas."
25
  ]
26
 
27
  def predict_emotion(text):
28
  try:
29
  if not text or not text.strip():
30
  return {"": 0.0}, "Veuillez entrer un texte."
31
- scores = get_clf()(text)[0] # [{'label': 'joy', 'score': 0.97}, ...]
32
  score_dict = {s["label"]: float(s["score"]) for s in scores}
33
  top = max(scores, key=lambda d: d["score"])
34
  notes = (
@@ -39,12 +39,15 @@ def predict_emotion(text):
39
  )
40
  return score_dict, notes
41
  except Exception as e:
42
- # Renvoie un message clair dans l’UI plutôt qu’un crash
43
  return {"error": 1.0}, f"Erreur interne : {e}"
44
 
45
  with gr.Blocks(title=APP_NAME) as demo:
46
  gr.Markdown(f"# {APP_NAME} — Détecteur d'émotions (texte)")
47
- txt = gr.Textbox(label="Votre texte", placeholder="Ex: Je suis déçue et un peu en colère par ce mail.", lines=3)
 
 
 
 
48
  btn = gr.Button("Analyser")
49
  out_scores = gr.Label(label="Scores (confiances)")
50
  out_notes = gr.Markdown()
@@ -52,5 +55,5 @@ with gr.Blocks(title=APP_NAME) as demo:
52
  btn.click(predict_emotion, txt, [out_scores, out_notes])
53
  txt.submit(predict_emotion, txt, [out_scores, out_notes])
54
 
55
- # IMPORTANT sur Hugging Face Spaces: ne pas appeler demo.launch()
56
  app = demo
 
2
  from transformers import pipeline
3
 
4
  APP_NAME = "MoodMapper"
5
+ MODEL_ID = "j-hartmann/emotion-english-distilroberta-base"
6
 
7
  _clf = None
8
  def get_clf():
 
17
  return _clf
18
 
19
  EXAMPLES = [
20
+ ["I just got the internship — I'm so happy!"],
21
+ ["Je suis déçue et un peu en colère par ce mail."],
22
+ ["This is fine, nothing special today."],
23
+ ["I'm worried about the deadline..."],
24
+ ["Quelle surprise ! Je ne m’y attendais pas."]
25
  ]
26
 
27
  def predict_emotion(text):
28
  try:
29
  if not text or not text.strip():
30
  return {"": 0.0}, "Veuillez entrer un texte."
31
+ scores = get_clf()(text)[0]
32
  score_dict = {s["label"]: float(s["score"]) for s in scores}
33
  top = max(scores, key=lambda d: d["score"])
34
  notes = (
 
39
  )
40
  return score_dict, notes
41
  except Exception as e:
 
42
  return {"error": 1.0}, f"Erreur interne : {e}"
43
 
44
  with gr.Blocks(title=APP_NAME) as demo:
45
  gr.Markdown(f"# {APP_NAME} — Détecteur d'émotions (texte)")
46
+ txt = gr.Textbox(
47
+ label="Votre texte",
48
+ placeholder="Ex: Je suis déçue et un peu en colère par ce mail.",
49
+ lines=3
50
+ )
51
  btn = gr.Button("Analyser")
52
  out_scores = gr.Label(label="Scores (confiances)")
53
  out_notes = gr.Markdown()
 
55
  btn.click(predict_emotion, txt, [out_scores, out_notes])
56
  txt.submit(predict_emotion, txt, [out_scores, out_notes])
57
 
58
+ # Ne pas lancer manuellement sur Hugging Face
59
  app = demo