DinoFrog commited on
Commit
400abf7
·
verified ·
1 Parent(s): b13d443

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -32
app.py CHANGED
@@ -1,3 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import requests
3
  import pandas as pd
@@ -34,46 +67,25 @@ def full_analysis(text, 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,7 +95,6 @@ Respond only with your explanation in a clear and concise paragraph.
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:
@@ -128,3 +139,4 @@ def launch_app():
128
 
129
  if __name__ == "__main__":
130
  launch_app()
 
 
1
+
2
+ Hugging Face's logo Hugging Face
3
+
4
+ Models
5
+ Datasets
6
+ Spaces
7
+ Posts
8
+ Docs
9
+ Enterprise
10
+ Pricing
11
+
12
+ Spaces:
13
+ DinoFrog
14
+ /
15
+ sentiment-analysis
16
+ App
17
+ Files
18
+ Community
19
+ Settings
20
+ sentiment-analysis
21
+ / app.py
22
+ DinoFrog's picture
23
+ DinoFrog
24
+ Update app.py
25
+ 9501ad8
26
+ verified
27
+ 8 minutes ago
28
+ raw
29
+ history
30
+ blame
31
+ edit
32
+ delete
33
+ 3.37 kB
34
  import gradio as gr
35
  import requests
36
  import pandas as pd
 
67
  if not text:
68
  return "Entrez une phrase.", "", 0, history
69
 
70
+ # 1. Détection sentiment par pipeline
71
+ result = classifier(text)[0]
72
+ detected_sentiment = result['label'].lower()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
+ # 2. Appel Zephyr pour explication basée sur ce sentiment
75
  prompt_explanation = f"""
76
  You are a financial analyst AI.
77
+ Based on the following financial news:
 
78
  \"{text}\"
79
+ Explain clearly why the sentiment is {detected_sentiment}.
80
+ Write a concise paragraph.
 
 
 
 
81
  """
82
  explanation = call_zephyr_api(prompt_explanation)
83
 
84
+ # 3. Calcul score de clarté
85
  clarity_score = textstat.flesch_reading_ease(explanation)
86
+ clarity_score = max(0, min(clarity_score, 100)) # Limité 0-100
87
 
88
+ # 4. Stocker historique
89
  history.append({
90
  "Texte": text,
91
  "Sentiment": detected_sentiment.capitalize(),
 
95
 
96
  return detected_sentiment.capitalize(), explanation, int(clarity_score), history
97
 
 
98
  # Fonction pour télécharger historique
99
  def download_history(history):
100
  if not history:
 
139
 
140
  if __name__ == "__main__":
141
  launch_app()
142
+