Anupam251272's picture
Update app.py
a356dab verified
import spacy
from spacy.cli import download
import nltk
import os
import gradio as gr
import torch
from sentence_transformers import SentenceTransformer
import PyPDF2
# Ensure NLTK 'punkt' tokenizer is downloaded
try:
nltk.data.find('tokenizers/punkt')
except LookupError:
print("Downloading NLTK 'punkt' tokenizer...")
nltk.download('punkt')
# Ensure spaCy 'en_core_web_sm' model is downloaded
try:
nlp = spacy.load("en_core_web_sm")
except OSError:
print("Downloading spaCy 'en_core_web_sm' model...")
download("en_core_web_sm")
nlp = spacy.load("en_core_web_sm")
# Load Sentence Transformer model
embedding_model = SentenceTransformer('all-MiniLM-L6-v2')
# Check for GPU availability
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Running on: {device}")
# Function to extract text from PDF
def extract_text_from_pdf(file_path):
try:
with open(file_path, 'rb') as file:
reader = PyPDF2.PdfReader(file)
text = ''.join(page.extract_text() for page in reader.pages)
return text
except Exception as e:
print(f"Error extracting PDF text: {e}")
return ""
# Placeholder function for CV skill analysis
def analyze_cv_skills(cv_text):
# Implement skill analysis and career recommendations
return "Skill analysis and recommendations coming soon!"
# Function to process CV and provide recommendations
def cv_skill_assessment(cv_file):
try:
cv_text = extract_text_from_pdf(cv_file.name)
if not cv_text.strip():
with open(cv_file.name, 'r', encoding='utf-8') as f:
cv_text = f.read()
assessment = analyze_cv_skills(cv_text)
return assessment
except Exception as e:
return f"Error processing CV: {str(e)}"
# Create Gradio Interface
def launch_cv_skill_assessment_app():
demo = gr.Interface(
fn=cv_skill_assessment,
inputs=gr.File(label="Upload Your CV (PDF/Text)", type="file"),
outputs=gr.Markdown(label="Career Recommendation Report"),
title="πŸš€ CV Skills Assessment AI",
description="""
Discover your ideal career path based on your CV!
- Upload your CV (PDF or Text file)
- AI analyzes your skills and experience
- Receive personalized career recommendations
""",
)
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
# Run the application
if __name__ == "__main__":
launch_cv_skill_assessment_app()