Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,27 +34,46 @@ def full_analysis(text, history):
|
|
34 |
if not text:
|
35 |
return "Entrez une phrase.", "", 0, history
|
36 |
|
37 |
-
# 1.
|
38 |
-
|
39 |
-
|
40 |
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
prompt_explanation = f"""
|
43 |
You are a financial analyst AI.
|
44 |
|
45 |
-
|
46 |
\"{text}\"
|
47 |
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
50 |
"""
|
51 |
explanation = call_zephyr_api(prompt_explanation)
|
52 |
|
53 |
-
# 3. Calcul score de clarté
|
54 |
clarity_score = textstat.flesch_reading_ease(explanation)
|
55 |
-
clarity_score = max(0, min(clarity_score, 100)) #
|
56 |
|
57 |
-
# 4.
|
58 |
history.append({
|
59 |
"Texte": text,
|
60 |
"Sentiment": detected_sentiment.capitalize(),
|
@@ -64,6 +83,7 @@ Write a concise paragraph.
|
|
64 |
|
65 |
return detected_sentiment.capitalize(), explanation, int(clarity_score), history
|
66 |
|
|
|
67 |
# Fonction pour télécharger historique
|
68 |
def download_history(history):
|
69 |
if not history:
|
|
|
34 |
if not text:
|
35 |
return "Entrez une phrase.", "", 0, history
|
36 |
|
37 |
+
# 1. Détecter le sentiment via pipeline (ou Zephyr selon ton architecture)
|
38 |
+
prompt_sentiment = f"""
|
39 |
+
You are a financial analyst AI specialized in analyzing news sentiment.
|
40 |
|
41 |
+
Given the following financial news:
|
42 |
+
\"{text}\"
|
43 |
+
|
44 |
+
Classify the overall sentiment into exactly one of the following categories:
|
45 |
+
- positive
|
46 |
+
- neutral
|
47 |
+
- negative
|
48 |
+
|
49 |
+
Only answer with the exact category name, and nothing else.
|
50 |
+
Be strict and do not be afraid to classify clearly.
|
51 |
+
"""
|
52 |
+
detected_sentiment = call_zephyr_api(prompt_sentiment).lower()
|
53 |
+
|
54 |
+
if detected_sentiment not in ["positive", "neutral", "negative"]:
|
55 |
+
detected_sentiment = "neutral"
|
56 |
+
|
57 |
+
# 2. Générer l'explication avec un prompt explicite
|
58 |
prompt_explanation = f"""
|
59 |
You are a financial analyst AI.
|
60 |
|
61 |
+
Given the following financial news:
|
62 |
\"{text}\"
|
63 |
|
64 |
+
Detected sentiment: {detected_sentiment}.
|
65 |
+
|
66 |
+
Now, write only your explanation why the sentiment is {detected_sentiment}.
|
67 |
+
Do not repeat the instructions or the prompt.
|
68 |
+
Respond only with your explanation in a clear and concise paragraph.
|
69 |
"""
|
70 |
explanation = call_zephyr_api(prompt_explanation)
|
71 |
|
72 |
+
# 3. Calcul du score de clarté
|
73 |
clarity_score = textstat.flesch_reading_ease(explanation)
|
74 |
+
clarity_score = max(0, min(clarity_score, 100)) # Borné 0-100
|
75 |
|
76 |
+
# 4. Stockage historique
|
77 |
history.append({
|
78 |
"Texte": text,
|
79 |
"Sentiment": detected_sentiment.capitalize(),
|
|
|
83 |
|
84 |
return detected_sentiment.capitalize(), explanation, int(clarity_score), history
|
85 |
|
86 |
+
|
87 |
# Fonction pour télécharger historique
|
88 |
def download_history(history):
|
89 |
if not history:
|