Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the sentiment analysis model from Hugging Face
|
| 5 |
+
classifier = pipeline("sentiment-analysis")
|
| 6 |
+
|
| 7 |
+
def predict_sentiment(text):
|
| 8 |
+
result = classifier(text)
|
| 9 |
+
return result[0]['label'], result[0]['score']
|
| 10 |
+
|
| 11 |
+
def main():
|
| 12 |
+
st.title("Text Classification App")
|
| 13 |
+
|
| 14 |
+
# User input
|
| 15 |
+
text_input = st.text_area("Enter text:", "Type your text here.")
|
| 16 |
+
|
| 17 |
+
# Prediction
|
| 18 |
+
if st.button("Predict"):
|
| 19 |
+
if text_input:
|
| 20 |
+
sentiment, confidence = predict_sentiment(text_input)
|
| 21 |
+
st.write(f"Sentiment: {sentiment}")
|
| 22 |
+
st.write(f"Confidence: {confidence:.4f}")
|
| 23 |
+
else:
|
| 24 |
+
st.warning("Please enter some text.")
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
main()
|