Spaces:
Runtime error
Runtime error
Peter Moc
commited on
Commit
•
df86432
1
Parent(s):
ba0bb8c
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,34 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
-
import torch
|
4 |
-
|
5 |
-
# Specify the
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
st.
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
if
|
27 |
-
|
28 |
-
label
|
29 |
-
st.write(f"
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
st.write("This application uses a fine-tuned BERT model to classify questions and statements.")
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Specify the Hugging Face model repository
|
6 |
+
model_name = "DanKoan/kiwi-classifier"
|
7 |
+
|
8 |
+
# Load the model and tokenizer from the Hugging Face Hub
|
9 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
|
12 |
+
# Function to predict the sentiment
|
13 |
+
def predict_sentiment(text):
|
14 |
+
inputs = tokenizer(text, return_tensors="pt")
|
15 |
+
with torch.no_grad():
|
16 |
+
outputs = model(**inputs)
|
17 |
+
probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
18 |
+
return torch.argmax(probs, dim=-1).item(), probs
|
19 |
+
|
20 |
+
# Streamlit interface
|
21 |
+
st.title("KIWI Classifier")
|
22 |
+
st.write("Enter a question or statement to classify:")
|
23 |
+
|
24 |
+
user_input = st.text_area("Your input", "")
|
25 |
+
if st.button("Classify"):
|
26 |
+
if user_input:
|
27 |
+
label, probabilities = predict_sentiment(user_input)
|
28 |
+
st.write(f"Prediction: {label}")
|
29 |
+
st.write(f"Probabilities: {probabilities.tolist()}")
|
30 |
+
else:
|
31 |
+
st.write("Please enter some text to classify.")
|
32 |
+
|
33 |
+
# Additional instructions or information
|
34 |
+
st.write("This application uses a fine-tuned BERT model to classify questions and statements.")
|
|