Peter Moc commited on
Commit
df86432
1 Parent(s): ba0bb8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -35
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 local paths where the model and tokenizer are saved
6
- model_dir = "path_to_save_model"
7
- tokenizer_dir = "path_to_save_tokenizer"
8
-
9
- # Load the model and tokenizer from the local directories
10
- model = AutoModelForSequenceClassification.from_pretrained(model_dir)
11
- tokenizer = AutoTokenizer.from_pretrained(tokenizer_dir)
12
-
13
- # Function to predict the sentiment
14
- def predict_sentiment(text):
15
- inputs = tokenizer(text, return_tensors="pt")
16
- with torch.no_grad():
17
- outputs = model(**inputs)
18
- probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
19
- return torch.argmax(probs, dim=-1).item(), probs
20
-
21
- # Streamlit interface
22
- st.title("KIWI Classifier")
23
- st.write("Enter a question or statement to classify:")
24
-
25
- user_input = st.text_area("Your input", "")
26
- if st.button("Classify"):
27
- if user_input:
28
- label, probabilities = predict_sentiment(user_input)
29
- st.write(f"Prediction: {label}")
30
- st.write(f"Probabilities: {probabilities.tolist()}")
31
- else:
32
- st.write("Please enter some text to classify.")
33
-
34
- # Additional instructions or information
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.")