Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,20 @@
|
|
1 |
-
|
|
|
2 |
import torch
|
3 |
|
4 |
-
# Load the
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import BertTokenizer, BertForSequenceClassification
|
3 |
import torch
|
4 |
|
5 |
+
# Load the pre-trained BERT model and tokenizer
|
6 |
+
model_name = "bert-base-uncased" # Replace with your specific model if needed
|
7 |
+
tokenizer = BertTokenizer.from_pretrained(model_name)
|
8 |
+
model = BertForSequenceClassification.from_pretrained(model_name)
|
9 |
+
|
10 |
+
# Streamlit UI
|
11 |
+
st.title("BERT Text Classification")
|
12 |
+
text_input = st.text_input("Enter text for classification:")
|
13 |
+
|
14 |
+
if text_input:
|
15 |
+
# Tokenize input
|
16 |
+
inputs = tokenizer(text_input, return_tensors="pt", truncation=True, padding=True, max_length=512)
|
17 |
+
with torch.no_grad():
|
18 |
+
logits = model(**inputs).logits
|
19 |
+
predicted_class = torch.argmax(logits, dim=1).item()
|
20 |
+
st.write(f"Predicted Class: {predicted_class}")
|