Update app.py
Browse files
app.py
CHANGED
@@ -8,11 +8,11 @@ import os
|
|
8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
9 |
|
10 |
# Fonction pour appeler l'API Zephyr
|
11 |
-
def call_zephyr_api(
|
12 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=hf_token)
|
13 |
try:
|
14 |
-
response = client.
|
15 |
-
return response
|
16 |
except Exception as e:
|
17 |
raise gr.Error(f"❌ Erreur d'appel API Hugging Face : {str(e)}")
|
18 |
|
@@ -49,13 +49,23 @@ def full_analysis(text, mode, detail_mode, count, history):
|
|
49 |
result = classifier(text)[0]
|
50 |
sentiment_output = f"Sentiment : {result['label']} (Score: {result['score']:.2f})"
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
explanation_fr = translator_to_fr(explanation_en, max_length=512)[0]['translation_text']
|
60 |
|
61 |
count += 1
|
|
|
8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
9 |
|
10 |
# Fonction pour appeler l'API Zephyr
|
11 |
+
def call_zephyr_api(prompt, hf_token=HF_TOKEN):
|
12 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=hf_token)
|
13 |
try:
|
14 |
+
response = client.text_generation(prompt, max_new_tokens=300)
|
15 |
+
return response
|
16 |
except Exception as e:
|
17 |
raise gr.Error(f"❌ Erreur d'appel API Hugging Face : {str(e)}")
|
18 |
|
|
|
49 |
result = classifier(text)[0]
|
50 |
sentiment_output = f"Sentiment : {result['label']} (Score: {result['score']:.2f})"
|
51 |
|
52 |
+
prompt = f"""<|system|>
|
53 |
+
You are a professional financial analyst AI.
|
54 |
+
</s>
|
55 |
+
<|user|>
|
56 |
+
Analyze the following financial news carefully:
|
57 |
+
"{text}"
|
58 |
+
|
59 |
+
The detected sentiment for this news is: {result['label'].lower()}.
|
60 |
+
|
61 |
+
Now, explain why the sentiment is {result['label'].lower()} using a logical, fact-based explanation.
|
62 |
+
Base your reasoning only on the given news text.
|
63 |
+
Do not repeat the news text or the prompt.
|
64 |
+
Respond only with your financial analysis in one clear paragraph.
|
65 |
+
Write in a clear and professional tone.
|
66 |
+
</s>
|
67 |
+
<|assistant|>"""
|
68 |
+
explanation_en = call_zephyr_api(prompt)
|
69 |
explanation_fr = translator_to_fr(explanation_en, max_length=512)[0]['translation_text']
|
70 |
|
71 |
count += 1
|