Spaces:
Sleeping
Sleeping
Download app.py from imalaiyke/Huggingface-demo: direct link, hf CLI and curl.
- Browser
- Download file 702 Bytes
-
https://huggingface.co/spaces/imalaiyke/Huggingface-demo/resolve/main/app.py
- Command line
-
hf download hf://spaces/imalaiyke/Huggingface-demo/app.py
-
curl -L -o app.py https://huggingface.co/spaces/imalaiyke/Huggingface-demo/resolve/main/app.py
702 Bytes
| import streamlit as st | |
| from transformers import pipeline | |
| # Load Hugging Face Sentiment Analysis pipeline | |
| sentiment_pipeline = pipeline("sentiment-analysis") | |
| # Streamlit app title | |
| st.title("Sentiment Analysis with Hugging Face") | |
| # Input text box | |
| input_text = st.text_area("Enter text to analyze:") | |
| # Analyze button | |
| if st.button("Analyze Sentiment"): | |
| if input_text: | |
| # Perform sentiment analysis | |
| result = sentiment_pipleline(input_text) | |
| # Display the result | |
| label = result[0]['label'] | |
| score = result[0]['score'] | |
| st.write(f"*Sentiment*: {label}") | |
| st.write(f"*Confidence*: {score:.2f}") | |
| else: | |
| st.write("Please enter some text.") |