import streamlit as st import tempfile import os from inference import predict_from_pdf # ========================= # PAGE CONFIG # ========================= st.set_page_config( page_title="AI Resume Category Classifier", page_icon="📄", layout="centered" ) # ========================= # SIDEBAR # ========================= st.sidebar.title("📄 Resume Parser – ML App") st.sidebar.write( """ This app uses a trained **machine learning model** to classify resumes into **job categories** based on their content. """ ) st.sidebar.markdown("---") st.sidebar.caption("Built as an internship project and refined for college submission.") # ========================= # MAIN CONTENT # ========================= st.title("📄 AI Resume Category Classifier") st.write( """ Upload a **PDF resume** and the model will predict its **category/domain**. """ ) uploaded_file = st.file_uploader( "Upload a resume (PDF file)", type=["pdf"], accept_multiple_files=False ) if uploaded_file is not None: st.info(f"Uploaded file: `{uploaded_file.name}`") if st.button("🔍 Analyze Resume"): with st.spinner("Reading and classifying the resume..."): # Save uploaded file to a temporary path with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp: tmp.write(uploaded_file.read()) temp_pdf_path = tmp.name try: predicted_label, proba_dict, raw_text = predict_from_pdf(temp_pdf_path) # Show predicted category st.success(f"Predicted Category: **{predicted_label}**") # Show probabilities (if available) if proba_dict is not None: st.subheader("Prediction Confidence") sorted_items = sorted(proba_dict.items(), key=lambda x: x[1], reverse=True) for label, prob in sorted_items: st.write(f"- {label}: `{prob:.2%}`") # Show extracted text preview with st.expander("🔎 View extracted resume text (preview)"): preview = (raw_text or "").strip() if preview: st.text(preview[:2000]) # first 2000 characters else: st.write("No text could be extracted from the PDF.") except Exception as e: st.error(f"❌ Error while processing the file: {e}") finally: # Clean up temp file if os.path.exists(temp_pdf_path): os.remove(temp_pdf_path) else: st.warning("Please upload a PDF resume to start.")