Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,57 +1,92 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
|
|
3 |
|
4 |
# Configuration de la page
|
5 |
st.set_page_config(
|
6 |
-
page_title="🌍 Analyse de Sentiment Multilingue",
|
7 |
-
page_icon="
|
8 |
layout="centered",
|
9 |
)
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
# Titre principal
|
12 |
-
st.title("
|
13 |
-
st.write("
|
14 |
|
15 |
-
#
|
16 |
with st.sidebar:
|
17 |
-
st.header("À propos
|
18 |
-
st.write("
|
|
|
|
|
|
|
|
|
19 |
st.markdown("---")
|
20 |
-
st.write("
|
21 |
|
22 |
-
#
|
23 |
@st.cache_resource
|
24 |
def load_model():
|
25 |
return pipeline("text-classification", model="tabularisai/multilingual-sentiment-analysis")
|
26 |
|
27 |
classifier = load_model()
|
28 |
|
29 |
-
#
|
30 |
-
st.subheader("✍️ Entrez
|
31 |
-
user_input = st.text_area("
|
32 |
|
33 |
-
# Bouton
|
34 |
-
if st.button("
|
35 |
-
if user_input.strip()
|
36 |
-
st.warning("⚠️ Merci d'entrer
|
37 |
else:
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
st.
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
# Footer
|
56 |
st.markdown("---")
|
57 |
-
st.markdown("🔗 [Voir le modèle
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
+
from langdetect import detect
|
4 |
+
import pandas as pd
|
5 |
|
6 |
# Configuration de la page
|
7 |
st.set_page_config(
|
8 |
+
page_title="🌍 Analyse de Sentiment Multilingue V2",
|
9 |
+
page_icon="🔎",
|
10 |
layout="centered",
|
11 |
)
|
12 |
|
13 |
+
# CSS personnalisé pour rendre l'app plus douce visuellement
|
14 |
+
st.markdown(
|
15 |
+
"""
|
16 |
+
<style>
|
17 |
+
.stApp {
|
18 |
+
background-color: #f0f2f6;
|
19 |
+
}
|
20 |
+
.big-font {
|
21 |
+
font-size:20px !important;
|
22 |
+
}
|
23 |
+
</style>
|
24 |
+
""",
|
25 |
+
unsafe_allow_html=True
|
26 |
+
)
|
27 |
+
|
28 |
# Titre principal
|
29 |
+
st.title("🔎 Analyseur de Sentiment Multilingue")
|
30 |
+
st.write("**Bienvenue !** Cette application détecte automatiquement la langue et analyse les sentiments de vos textes. 📖")
|
31 |
|
32 |
+
# Sidebar d'information
|
33 |
with st.sidebar:
|
34 |
+
st.header("📚 À propos de l'application")
|
35 |
+
st.write("""
|
36 |
+
- Modèle IA : tabularisai/multilingual-sentiment-analysis
|
37 |
+
- Analyse de texte rapide
|
38 |
+
- Détection de la langue
|
39 |
+
""")
|
40 |
st.markdown("---")
|
41 |
+
st.write("Réalisé avec ❤️ en Python et Streamlit")
|
42 |
|
43 |
+
# Charger le modèle
|
44 |
@st.cache_resource
|
45 |
def load_model():
|
46 |
return pipeline("text-classification", model="tabularisai/multilingual-sentiment-analysis")
|
47 |
|
48 |
classifier = load_model()
|
49 |
|
50 |
+
# Entrée utilisateur
|
51 |
+
st.subheader("✍️ Entrez vos phrases :")
|
52 |
+
user_input = st.text_area("Entrez plusieurs phrases séparées par un point-virgule ';'", height=150)
|
53 |
|
54 |
+
# Bouton
|
55 |
+
if st.button("🔍 Lancer l'analyse"):
|
56 |
+
if not user_input.strip():
|
57 |
+
st.warning("⚠️ Merci d'entrer au moins une phrase.")
|
58 |
else:
|
59 |
+
phrases = [phrase.strip() for phrase in user_input.split(';') if phrase.strip()]
|
60 |
+
|
61 |
+
st.info(f"Nombre de phrases détectées : {len(phrases)}")
|
62 |
+
|
63 |
+
results = []
|
64 |
+
|
65 |
+
with st.spinner("Analyse en cours... ⏳"):
|
66 |
+
for phrase in phrases:
|
67 |
+
try:
|
68 |
+
lang = detect(phrase)
|
69 |
+
except:
|
70 |
+
lang = "indéterminée"
|
71 |
+
|
72 |
+
analysis = classifier(phrase)[0]
|
73 |
+
results.append({
|
74 |
+
"Texte": phrase,
|
75 |
+
"Langue": lang,
|
76 |
+
"Sentiment": analysis["label"],
|
77 |
+
"Score": round(analysis["score"], 2)
|
78 |
+
})
|
79 |
+
|
80 |
+
# Affichage sous forme de tableau
|
81 |
+
df_results = pd.DataFrame(results)
|
82 |
+
st.dataframe(df_results)
|
83 |
+
|
84 |
+
# Résultats graphiques
|
85 |
+
st.subheader("📊 Visualisation des scores de confiance")
|
86 |
+
st.bar_chart(df_results.set_index("Texte")["Score"])
|
87 |
+
|
88 |
+
st.success("✅ Analyse terminée avec succès !")
|
89 |
|
90 |
# Footer
|
91 |
st.markdown("---")
|
92 |
+
st.markdown("🔗 [Voir le modèle Hugging Face](https://huggingface.co/tabularisai/multilingual-sentiment-analysis) | Projet open-source disponible sur demande.")
|