Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,42 @@
|
|
1 |
from transformers import pipeline
|
|
|
2 |
import gradio as gr
|
3 |
|
4 |
-
# Chargement du modèle
|
5 |
classifier = pipeline(
|
6 |
"sentiment-analysis",
|
7 |
model="mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis"
|
8 |
)
|
9 |
|
10 |
-
#
|
|
|
|
|
11 |
def analyze_sentiment(text):
|
12 |
if not text:
|
13 |
return "Entrez une phrase."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
result = classifier(text)[0]
|
15 |
return f"Sentiment : {result['label']} (Score: {result['score']:.2f})"
|
16 |
|
17 |
# Interface utilisateur
|
18 |
iface = gr.Interface(
|
19 |
fn=analyze_sentiment,
|
20 |
-
inputs=gr.Textbox(lines=
|
21 |
outputs="text",
|
22 |
-
title="Analyse de Sentiment Financier
|
23 |
-
description="Entrez une news financière
|
24 |
)
|
25 |
|
26 |
-
# Lancement local
|
27 |
iface.launch()
|
|
|
1 |
from transformers import pipeline
|
2 |
+
from langdetect import detect
|
3 |
import gradio as gr
|
4 |
|
5 |
+
# Chargement du modèle de sentiment
|
6 |
classifier = pipeline(
|
7 |
"sentiment-analysis",
|
8 |
model="mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis"
|
9 |
)
|
10 |
|
11 |
+
# Chargement du modèle de traduction FR->EN (peut aussi servir pour d'autres langues si tu veux étendre)
|
12 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-mul-en")
|
13 |
+
|
14 |
def analyze_sentiment(text):
|
15 |
if not text:
|
16 |
return "Entrez une phrase."
|
17 |
+
|
18 |
+
try:
|
19 |
+
# Détection de la langue
|
20 |
+
lang = detect(text)
|
21 |
+
except:
|
22 |
+
lang = "unknown"
|
23 |
+
|
24 |
+
# Traduction si la langue n'est pas l'anglais
|
25 |
+
if lang != "en":
|
26 |
+
text = translator(text, max_length=512)[0]['translation_text']
|
27 |
+
|
28 |
+
# Analyse de sentiment
|
29 |
result = classifier(text)[0]
|
30 |
return f"Sentiment : {result['label']} (Score: {result['score']:.2f})"
|
31 |
|
32 |
# Interface utilisateur
|
33 |
iface = gr.Interface(
|
34 |
fn=analyze_sentiment,
|
35 |
+
inputs=gr.Textbox(lines=4, placeholder="Entrez une actualité financière ici..."),
|
36 |
outputs="text",
|
37 |
+
title="Analyse de Sentiment Financier",
|
38 |
+
description="Entrez une news financière. Le modèle détecte automatiquement la langue et analyse le sentiment."
|
39 |
)
|
40 |
|
41 |
+
# Lancement local
|
42 |
iface.launch()
|