Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +17 -8
src/streamlit_app.py
CHANGED
|
@@ -1,13 +1,22 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 3 |
|
| 4 |
+
# Load model and tokenizer
|
| 5 |
+
model_name = "prd101-wd/phi1_5-sentiment-merged"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 8 |
|
| 9 |
+
# Create a pipeline
|
| 10 |
+
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
| 11 |
|
| 12 |
+
# Streamlit UI
|
| 13 |
+
st.title("Sentiment Classifier")
|
| 14 |
|
| 15 |
+
text = st.text_area("Enter text to classify:")
|
| 16 |
+
|
| 17 |
+
if st.button("Classify"):
|
| 18 |
+
if text.strip():
|
| 19 |
+
result = classifier(text)[0]
|
| 20 |
+
st.markdown(f"**Label:** {result['label']} \n**Score:** {result['score']:.4f}")
|
| 21 |
+
else:
|
| 22 |
+
st.warning("Please enter some text.")
|