Spaces:
Sleeping
Sleeping
Download app.py from Rebecva/ResumeAnalyzer: direct link, hf CLI and curl.
- Browser
- Download file 2.97 kB
-
https://huggingface.co/spaces/Rebecva/ResumeAnalyzer/resolve/main/app.py
- Command line
-
hf download hf://spaces/Rebecva/ResumeAnalyzer/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Rebecva/ResumeAnalyzer/resolve/main/app.py
2.97 kB
| import gradio as gr | |
| from groq import Groq | |
| from pypdf import PdfReader | |
| import docx | |
| # Paste your Groq API key here | |
| GROQ_API_KEY = "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" | |
| client = Groq(api_key=GROQ_API_KEY) | |
| def extract_text_from_pdf(file_path): | |
| reader = PdfReader(file_path) | |
| text = "" | |
| for page in reader.pages: | |
| page_text = page.extract_text() | |
| if page_text: | |
| text += page_text + "\n" | |
| return text | |
| def extract_text_from_docx(file_path): | |
| document = docx.Document(file_path) | |
| text = "" | |
| for paragraph in document.paragraphs: | |
| text += paragraph.text + "\n" | |
| return text | |
| def analyze_resume(resume_file, job_role): | |
| try: | |
| if GROQ_API_KEY == "GROQ KEY": | |
| return "Please paste your actual Groq API key." | |
| if resume_file is None: | |
| return "Please upload a resume." | |
| if job_role is None or job_role.strip() == "": | |
| return "Please enter a target job role." | |
| file_path = resume_file.name | |
| if file_path.lower().endswith(".pdf"): | |
| resume_text = extract_text_from_pdf(file_path) | |
| elif file_path.lower().endswith(".docx"): | |
| resume_text = extract_text_from_docx(file_path) | |
| else: | |
| return "Please upload only PDF or DOCX file." | |
| if resume_text.strip() == "": | |
| return "Could not extract text from the resume. Try another PDF/DOCX file." | |
| prompt = f""" | |
| You are an expert HR recruiter and career advisor. | |
| Analyze the following resume for this target role: | |
| Target Role: | |
| {job_role} | |
| Resume: | |
| {resume_text} | |
| Give the output in this exact format: | |
| 1. Overall Resume Summary | |
| 2. Key Strengths | |
| 3. Skill Gaps | |
| 4. Missing Keywords | |
| 5. Job Fit Score out of 100 | |
| 6. Resume Improvement Suggestions | |
| 7. Suggested Professional Summary | |
| 8. Interview Preparation Topics | |
| Use simple, clear, and professional language. | |
| """ | |
| response = client.chat.completions.create( | |
| model="llama-3.1-8b-instant", | |
| messages=[ | |
| { | |
| "role": "user", | |
| "content": prompt | |
| } | |
| ], | |
| temperature=0.3, | |
| max_tokens=900 | |
| ) | |
| return response.choices[0].message.content | |
| except Exception as e: | |
| return "Error occurred: " + str(e) | |
| demo = gr.Interface( | |
| fn=analyze_resume, | |
| inputs=[ | |
| gr.File( | |
| label="Upload Resume", | |
| file_types=[".pdf", ".docx"] | |
| ), | |
| gr.Textbox( | |
| label="Target Job Role", | |
| placeholder="Example: Assistant Professor in ECE, Data Scientist, AI Engineer" | |
| ) | |
| ], | |
| outputs=gr.Textbox( | |
| lines=22, | |
| label="Resume Analysis Report" | |
| ), | |
| title="AI Resume Analyzer", | |
| description="Upload your resume and enter a target job role. The app analyzes strengths, gaps, keywords, and job-fit score." | |
| ) | |
| demo.launch(share=True, debug=True) |