Spaces:
Build error
Build error
| import streamlit as st | |
| from transformers import pipeline | |
| # Load the sentiment analysis model from Hugging Face | |
| classifier = pipeline("sentiment-analysis") | |
| def predict_sentiment(text): | |
| result = classifier(text) | |
| return result[0]['label'], result[0]['score'] | |
| def main(): | |
| st.title("Text Classification App") | |
| # User input | |
| text_input = st.text_area("Enter text:", "Type your text here.") | |
| # Prediction | |
| if st.button("Predict"): | |
| if text_input: | |
| sentiment, confidence = predict_sentiment(text_input) | |
| st.write(f"Sentiment: {sentiment}") | |
| st.write(f"Confidence: {confidence:.4f}") | |
| else: | |
| st.warning("Please enter some text.") | |
| if __name__ == "__main__": | |
| main() |