TFToodie commited on
Commit
6759ca3
·
verified ·
1 Parent(s): aafcf87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -1,6 +1,20 @@
1
- from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
 
2
  import torch
3
 
4
- # Load the tokenizer and model
5
- tokenizer = AutoTokenizer.from_pretrained("jjzha/jobbert_knowledge_extraction")
6
- model = AutoModelForTokenClassification.from_pretrained("jjzha/jobbert_knowledge_extraction")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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}")