Download app.py from Amna252003/semantic-analyzer-practice: direct link, hf CLI and curl.
- Browser
- Download file 805 Bytes
-
https://huggingface.co/spaces/Amna252003/semantic-analyzer-practice/resolve/main/app.py
- Command line
-
hf download hf://spaces/Amna252003/semantic-analyzer-practice/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Amna252003/semantic-analyzer-practice/resolve/main/app.py
805 Bytes
| import streamlit as st | |
| from transformers import pipeline | |
| st.set_page_config(page_title="Semantic Analyzer") | |
| st.title("Semantic Analyzer") | |
| st.write("Analyze the sentiment of your text using NLP.") | |
| def load_model(): | |
| return pipeline( | |
| "sentiment-analysis", | |
| model="distilbert/distilbert-base-uncased-finetuned-sst-2-english", | |
| device=-1 | |
| ) | |
| text = st.text_area("Enter a sentence or paragraph") | |
| if st.button("Analyze"): | |
| if text.strip(): | |
| with st.spinner("Analyzing text..."): | |
| model = load_model() | |
| result = model(text[:5000])[0] | |
| st.subheader("Result") | |
| st.write("Sentiment:", result["label"]) | |
| st.write("Confidence:", f"{result['score']:.2%}") | |
| else: | |
| st.warning("Please enter some text.") | |