Spaces:
Configuration error
Configuration error
Download app.py from dkshah/mypythonapp: direct link, hf CLI and curl.
- Browser
- Download file 3.09 kB
-
https://huggingface.co/spaces/dkshah/mypythonapp/resolve/main/app.py
- Command line
-
hf download hf://spaces/dkshah/mypythonapp/app.py
-
curl -L -o app.py https://huggingface.co/spaces/dkshah/mypythonapp/resolve/main/app.py
3.09 kB
| 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() | |