File size: 3,093 Bytes
840f8bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import streamlit as st
import os
from utils.resume_parser import parse_resume
from utils.ai_summarizer import summarize_resume

# Set page config
st.set_page_config(
    page_title="Resume Parser & Summarizer",
    page_icon="📄",
    layout="wide"
)

def main():
    st.title("📄 Resume Parser & Summarizer")
    st.write("Upload a resume (PDF or DOCX) to extract and summarize key information.")
    
    # Create necessary directories
    os.makedirs("data", exist_ok=True)
    
    # Sidebar: Hugging Face Settings
    st.sidebar.header("Hugging Face Settings")
    default_model = "facebook/bart-large-cnn"
    hf_model = st.sidebar.text_input(
        "Summarization model (repo id)", value=default_model,
        help="e.g., facebook/bart-large-cnn, sshleifer/distilbart-cnn-12-6"
    )
    # Prefer token from secrets, then environment, then user input
    secrets_token = st.secrets.get("HF_TOKEN") if hasattr(st, "secrets") else None
    env_token = os.environ.get("HF_TOKEN")
    token_placeholder = "Using st.secrets['HF_TOKEN']" if secrets_token else ("Using env HF_TOKEN" if env_token else "Paste your token (optional)")
    input_token = st.sidebar.text_input("Hugging Face API Token", value="", type="password", help=token_placeholder)
    hf_token = input_token or secrets_token or env_token
    
    # File uploader
    uploaded_file = st.file_uploader("Choose a resume file", type=["pdf", "docx"])
    
    if uploaded_file is not None:
        # Save the uploaded file
        file_path = os.path.join("data", uploaded_file.name)
        with open(file_path, "wb") as f:
            f.write(uploaded_file.getbuffer())
        
        st.success(f"Successfully uploaded {uploaded_file.name}")
        
        # Parse the resume
        with st.spinner("Parsing resume..."):
            resume_data = parse_resume(file_path)
        
        if resume_data:
            st.subheader("Extracted Information")
            
            # Display basic info
            col1, col2 = st.columns(2)
            with col1:
                if resume_data.get('name'):
                    st.markdown(f"**Name:** {resume_data['name']}")
                if resume_data.get('email'):
                    st.markdown(f"**Email:** {resume_data['email']}")
                if resume_data.get('phone'):
                    st.markdown(f"**Phone:** {resume_data['phone']}")
            
            with col2:
                if resume_data.get('skills'):
                    st.markdown("**Skills:**")
                    st.write(", ".join(resume_data['skills']))
            
            # Generate and display summary
            with st.spinner("Generating summary..."):
                summary = summarize_resume(resume_data, hf_model=hf_model, hf_token=hf_token)
                st.subheader("AI-Powered Summary")
                st.write(summary)
            
            # Display full text (collapsible)
            with st.expander("View Full Extracted Text"):
                st.text(resume_data.get('raw_text', 'No text extracted'))

if __name__ == "__main__":
    main()