DinoFrog commited on
Commit
6741a19
·
verified ·
1 Parent(s): 882a689

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -19,10 +19,7 @@ def call_zephyr_api(prompt, hf_token=HF_TOKEN):
19
  response.raise_for_status()
20
  return response.json()[0]["generated_text"]
21
  except Exception as e:
22
- error_msg = f"❌ Erreur d'appel API Hugging Face : {str(e)}"
23
- if isinstance(e, requests.exceptions.RequestException):
24
- error_msg += f" (Code de statut : {e.response.status_code if e.response else 'N/A'})"
25
- raise gr.Error(error_msg)
26
 
27
  # Chargement du modèle de sentiment
28
  classifier = pipeline("sentiment-analysis", model="mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis")
@@ -57,20 +54,22 @@ def full_analysis(text, mode, detail_mode, count, history):
57
  result = classifier(text)[0]
58
  sentiment_output = f"Sentiment : {result['label']} (Score: {result['score']:.2f})"
59
 
60
- prompt = f"""
61
- You are a professional financial analyst AI.
 
 
 
 
62
 
63
- Analyze the following financial news carefully:
64
- "{text}"
65
 
66
- The detected sentiment for this news is: {result['label'].lower()}.
67
-
68
- Now, explain why the sentiment is {result['label'].lower()} using a logical, fact-based explanation.
69
- Base your reasoning only on the given news text.
70
- Do not repeat the news text or the prompt.
71
- Respond only with your financial analysis in one clear paragraph.
72
- Write in a clear and professional tone.
73
- """
74
 
75
  explanation_en = call_zephyr_api(prompt)
76
  explanation_fr = translator_to_fr(explanation_en, max_length=512)[0]['translation_text']
@@ -143,7 +142,6 @@ def launch_app():
143
  outputs=[sentiment_output, explanation_output_en, explanation_output_fr, count, history]
144
  )
145
 
146
-
147
  download_btn.click(
148
  download_history,
149
  inputs=[history],
@@ -153,4 +151,4 @@ def launch_app():
153
  iface.launch()
154
 
155
  if __name__ == "__main__":
156
- launch_app()
 
19
  response.raise_for_status()
20
  return response.json()[0]["generated_text"]
21
  except Exception as e:
22
+ raise gr.Error(f"❌ Erreur d'appel API Hugging Face : {str(e)}")
 
 
 
23
 
24
  # Chargement du modèle de sentiment
25
  classifier = pipeline("sentiment-analysis", model="mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis")
 
54
  result = classifier(text)[0]
55
  sentiment_output = f"Sentiment : {result['label']} (Score: {result['score']:.2f})"
56
 
57
+ prompt = f"""<|system|>
58
+ You are a professional financial analyst AI.
59
+ </s>
60
+ <|user|>
61
+ Analyze the following financial news carefully:
62
+ "{text}"
63
 
64
+ The detected sentiment for this news is: {result['label'].lower()}.
 
65
 
66
+ Now, explain why the sentiment is {result['label'].lower()} using a logical, fact-based explanation.
67
+ Base your reasoning only on the given news text.
68
+ Do not repeat the news text or the prompt.
69
+ Respond only with your financial analysis in one clear paragraph.
70
+ Write in a clear and professional tone.
71
+ </s>
72
+ <|assistant|>"""
 
73
 
74
  explanation_en = call_zephyr_api(prompt)
75
  explanation_fr = translator_to_fr(explanation_en, max_length=512)[0]['translation_text']
 
142
  outputs=[sentiment_output, explanation_output_en, explanation_output_fr, count, history]
143
  )
144
 
 
145
  download_btn.click(
146
  download_history,
147
  inputs=[history],
 
151
  iface.launch()
152
 
153
  if __name__ == "__main__":
154
+ launch_app()