Spaces:
Sleeping
Sleeping
File size: 3,181 Bytes
32664df 02e8256 32664df c90ba3c 32664df 6e9cf6b 4059d3c 9f8462a 6e9cf6b 4059d3c 6e9cf6b a7cbe84 6e9cf6b 4059d3c a7cbe84 6e9cf6b c90ba3c 8215942 8bca00c 1da82bb 6e9cf6b c90ba3c 6e9cf6b a7cbe84 1da82bb 6e9cf6b adcde56 1da82bb adcde56 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | 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)
|