Spaces:
Sleeping
Sleeping
Pyamas
commited on
Commit
·
a19272e
1
Parent(s):
cf32a14
Add model files
Browse files
app.py
CHANGED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
+
import torch
|
4 |
+
|
5 |
+
model_name = "."
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
8 |
+
|
9 |
+
st.title("Sentiment Classifier")
|
10 |
+
|
11 |
+
user_input = st.text_input("Enter text to classify:")
|
12 |
+
|
13 |
+
if st.button("Classify"):
|
14 |
+
if user_input:
|
15 |
+
inputs = tokenizer(user_input, return_tensors="pt")
|
16 |
+
with torch.no_grad():
|
17 |
+
outputs = model(**inputs)
|
18 |
+
probs = outputs.logits.softmax(dim=-1).tolist()[0]
|
19 |
+
|
20 |
+
st.write(f"Positive: {probs[1]:.4f}")
|
21 |
+
st.write(f"Negative: {probs[0]:.4f}")
|
22 |
+
else:
|
23 |
+
st.write("Please enter some text to classify.")
|