prd101-wd commited on
Commit
54f1bf7
·
verified ·
1 Parent(s): 22cc418

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- classifier = pipeline("text-classification", model="prd101-wd/phi1_5-sentiment-merged")
 
 
 
5
 
6
- st.title("Text Classifier")
 
7
 
8
- text = st.text_area("Enter text:")
 
9
 
10
- if text:
11
- result = classifier(text)[0]
12
- st.write(f"**Label:** {result['label']}")
13
- st.write(f"**Confidence:** {result['score']:.4f}")
 
 
 
 
 
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.")