Update app.py
Browse files
app.py
CHANGED
@@ -39,8 +39,8 @@ async def call_zephyr_api(prompt, mode, hf_token=HF_TOKEN):
|
|
39 |
st.error(f"❌ Erreur d'appel API Hugging Face : {str(e)}")
|
40 |
return None
|
41 |
|
42 |
-
# Chargement du modèle de sentiment
|
43 |
-
classifier = pipeline("sentiment-analysis", model="mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis")
|
44 |
|
45 |
# Modèles de traduction
|
46 |
translator_to_en = pipeline("translation", model="Helsinki-NLP/opus-mt-mul-en")
|
@@ -88,7 +88,7 @@ def create_sentiment_gauge(sentiment, score):
|
|
88 |
"""
|
89 |
return html
|
90 |
|
91 |
-
# Fonction d'analyse (avec
|
92 |
async def full_analysis(text, mode, detail_mode, history):
|
93 |
if not text:
|
94 |
st.warning("Entrez une phrase.")
|
@@ -111,9 +111,9 @@ async def full_analysis(text, mode, detail_mode, history):
|
|
111 |
else:
|
112 |
text_en = text
|
113 |
|
114 |
-
# Étape 2 : Analyse du sentiment
|
115 |
status_text.write("Analyse en cours... (Étape 2 : Analyse du sentiment)")
|
116 |
-
result =
|
117 |
result = result[0]
|
118 |
sentiment_output = f"Sentiment prédictif : {result['label']} (Score: {result['score']:.2f})"
|
119 |
sentiment_gauge = create_sentiment_gauge(result['label'], result['score'])
|
@@ -238,7 +238,7 @@ def main():
|
|
238 |
|
239 |
# Résultats
|
240 |
if analyze_btn and input_text:
|
241 |
-
# Exécuter l'analyse
|
242 |
loop = asyncio.new_event_loop()
|
243 |
asyncio.set_event_loop(loop)
|
244 |
result = loop.run_until_complete(full_analysis(input_text, mode_selector, detail_mode_selector, st.session_state.history))
|
@@ -256,7 +256,7 @@ def main():
|
|
256 |
st.text_area("Sentiment prédictif", sentiment_output, height=100, disabled=True)
|
257 |
st.markdown(sentiment_gauge, unsafe_allow_html=True)
|
258 |
st.text_area("Votre question", displayed_prompt, height=100, disabled=True)
|
259 |
-
st.text_area("Progression", progress_message, height=70, disabled=True)
|
260 |
with col_results2:
|
261 |
st.text_area("Explication en anglais", explanation_en, height=200, disabled=True)
|
262 |
st.text_area("Explication en français", explanation_fr, height=200, disabled=True)
|
|
|
39 |
st.error(f"❌ Erreur d'appel API Hugging Face : {str(e)}")
|
40 |
return None
|
41 |
|
42 |
+
# Chargement du modèle de sentiment (forcé sur CPU)
|
43 |
+
classifier = pipeline("sentiment-analysis", model="mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis", device="cpu")
|
44 |
|
45 |
# Modèles de traduction
|
46 |
translator_to_en = pipeline("translation", model="Helsinki-NLP/opus-mt-mul-en")
|
|
|
88 |
"""
|
89 |
return html
|
90 |
|
91 |
+
# Fonction d'analyse (avec exécution synchrone pour le classifieur)
|
92 |
async def full_analysis(text, mode, detail_mode, history):
|
93 |
if not text:
|
94 |
st.warning("Entrez une phrase.")
|
|
|
111 |
else:
|
112 |
text_en = text
|
113 |
|
114 |
+
# Étape 2 : Analyse du sentiment (exécution synchrone)
|
115 |
status_text.write("Analyse en cours... (Étape 2 : Analyse du sentiment)")
|
116 |
+
result = classifier(text_en) # Exécution synchrone
|
117 |
result = result[0]
|
118 |
sentiment_output = f"Sentiment prédictif : {result['label']} (Score: {result['score']:.2f})"
|
119 |
sentiment_gauge = create_sentiment_gauge(result['label'], result['score'])
|
|
|
238 |
|
239 |
# Résultats
|
240 |
if analyze_btn and input_text:
|
241 |
+
# Exécuter l'analyse
|
242 |
loop = asyncio.new_event_loop()
|
243 |
asyncio.set_event_loop(loop)
|
244 |
result = loop.run_until_complete(full_analysis(input_text, mode_selector, detail_mode_selector, st.session_state.history))
|
|
|
256 |
st.text_area("Sentiment prédictif", sentiment_output, height=100, disabled=True)
|
257 |
st.markdown(sentiment_gauge, unsafe_allow_html=True)
|
258 |
st.text_area("Votre question", displayed_prompt, height=100, disabled=True)
|
259 |
+
st.text_area("Progression", progress_message, height=70, disabled=True)
|
260 |
with col_results2:
|
261 |
st.text_area("Explication en anglais", explanation_en, height=200, disabled=True)
|
262 |
st.text_area("Explication en français", explanation_fr, height=200, disabled=True)
|