Piyapawashe/RESUME_CLASSIFICATION_BERT
0
1import gradio as gr2import torch3import pickle4from transformers import BertTokenizer, BertForSequenceClassification5 6# Load model and tokenizer from local folder7def load_model():8 model = BertForSequenceClassification.from_pretrained("./")9 tokenizer = BertTokenizer.from_pretrained("./")10 return model, tokenizer11 12# Load label encoder13def load_encoder():14 with open("label_encoder.pkl", "rb") as f:15 return pickle.load(f)16 17model, tokenizer = load_model()18label_encoder = load_encoder()19 20# Prediction function21def predict_resume(text):22 if text.strip() == "":23 return "⚠️ Please enter resume text"24 25 inputs = tokenizer(26 text,27 return_tensors="pt",28 truncation=True,29 padding=True,30 max_length=51231 )32 33 with torch.no_grad():34 outputs = model(**inputs)35 36 pred_id = torch.argmax(outputs.logits, dim=1).item()37 category = label_encoder.inverse_transform([pred_id])[0]38 39 confidence = torch.softmax(outputs.logits, dim=1)[0][pred_id].item()40 41 return f"🔮 Predicted Category: **{category}**\n📊 Confidence: {confidence:.2%}"42 43# Gradio Interface44interface = gr.Interface(45 fn=predict_resume, # <-- FIXED: added function here46 inputs=gr.Textbox(lines=10, placeholder="Paste resume text here..."),47 outputs="text",48 title="Resume Classification using BERT",49 description="This app classifies resumes into job categories using a fine-tuned BERT model.",50 css="style.css" # optional external CSS file51)52 53interface.launch()54 