Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import pipeline | |
| # Charger le pipeline d'analyse de sentiments pour le français | |
| sentiment_analyzer = pipeline('sentiment-analysis', model='nlptown/bert-base-multilingual-uncased-sentiment') | |
| # Créer l'interface Streamlit | |
| st.title("Analyse de sentiments d'un texte") | |
| texte = st.text_area("Entrez un texte pour l'analyser") | |
| # Ajouter un bouton "Valider" | |
| if st.button("Valider"): | |
| if texte: | |
| # Effectuer l'analyse de sentiment sur le texte entré | |
| resultat = sentiment_analyzer(texte) | |
| #st.write(f"{resultat[0]}") | |
| # Récupérer le sentiment et le score de confiance | |
| sentiment = resultat[0]['label'] | |
| confiance = resultat[0]['score'] | |
| # Formater la phrase et l'afficher avec st.write | |
| phrase = texte | |
| #st.write(f"Phrase: {phrase} -> Sentiment: {sentiment} (Confiance: {confiance:.2f})") | |
| # Déterminer le nombre d'étoiles en fonction du sentiment | |
| if sentiment == "5 stars": | |
| stars = 5 # Très Positif | |
| star_color = "darkgreen" | |
| mood = "Très positif" | |
| if sentiment == "4 stars": | |
| stars = 4 # Positif | |
| star_color = "lightgreen" | |
| mood = "Assez positif" | |
| if sentiment == "3 stars": | |
| stars = 3 # Neutre | |
| star_color = "gold" | |
| mood = "Neutre" | |
| if sentiment == "2 stars": | |
| stars = 2 # Plutôt négatif | |
| star_color = "orange" | |
| mood = "Plutôt négatif" | |
| if sentiment == "1 star": | |
| stars = 1 # Très négatif | |
| star_color = "red" # Vert pour 5 étoiles | |
| mood = "Très négatif" | |
| # Créer un affichage d'étoiles avec des couleurs | |
| #star_rating = "".join([f"<span style='color:{star_color};'>★</span>" for _ in range(stars)]) + "☆" * (5 - stars) | |
| #star_rating = f"<h3>{''.join([f'<span style=\"color:{star_color};\">★</span>' for _ in range(stars)])}{'☆' * (5 - stars)}</h3>" | |
| #star_rating = f"<h3>''.join([f'<span style=\'color:{star_color};\'>★</span>' for _ in range({stars})])'☆' * (5 - {stars})</h3>" | |
| # Afficher les étoiles avec couleur | |
| #st.markdown(star_rating, unsafe_allow_html=True) | |
| # Afficher le sentiment avec une coloration spécifique | |
| st.markdown(f"<h3 style='color:{star_color};'>Sentiment: {mood}</h3>", unsafe_allow_html=True) | |
| # Affichage de la confiance sous forme de jauge (progress bar) | |
| # Affichage de la confiance avec un texte explicatif | |
| #st.subheader("Confiance de l'analyse") | |
| if confiance < 0.3: | |
| color = "red" | |
| message = "Confiance faible" | |
| elif confiance < 0.7: | |
| color = "orange" | |
| message = "Confiance moyenne" | |
| else: | |
| color = "green" | |
| message = "Confiance élevée" | |
| st.markdown(f"<h3 style='color:{color};'>{message} ({confiance * 100:.0f}%)</h3>", unsafe_allow_html=True) | |
| #st.subheader("Confiance de l'analyse") | |
| #st.progress(confiance) # Jauge de progression de la confiance (entre 0 et 1) | |