dev_NLP / app.py
ahmadouna's picture
Update app.py
b98e93a
raw
history blame
No virus
1.01 kB
import streamlit as st
from transformers import pipeline
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randn(50, 20), columns=("col %d" % i for i in range(20)))
st.dataframe(df) # Same as st.write(df)
# Initialisation de la pipeline de classification à zéro tir
classifier = pipeline("zero-shot-classification", model="morit/french_xlm_xnli")
# Création d'une entrée pour le texte à analyser
text = st.text_input('Entrer le texte à analyser')
# Labels candidats pour la classification
candidate_labels = ["commentaire positive", "commentaire négative"]
# Modèle de phrase pour la formation de l'hypothèse
hypothesis_template = "Cet exemple est un {}."
# Exécution de la classification seulement si du texte est entré
if text and candidate_labels: # Vérifier si du texte et au moins une étiquette sont présents
st.write(classifier(text, candidate_labels, hypothesis_template=hypothesis_template))
else:
st.write("Veuillez entrer du texte pour l'analyse.")