Spaces:
Runtime error
Runtime error
Download app.py from omidk414/resume_optimizer_with_html_template: direct link, hf CLI and curl.
- Browser
- Download file 2.41 kB
-
https://huggingface.co/spaces/omidk414/resume_optimizer_with_html_template/resolve/main/app.py
- Command line
-
hf download hf://spaces/omidk414/resume_optimizer_with_html_template/app.py
-
curl -L -o app.py https://huggingface.co/spaces/omidk414/resume_optimizer_with_html_template/resolve/main/app.py
2.41 kB
| import os | |
| import gradio as gr | |
| import numpy as np | |
| import tensorflow as tf | |
| from transformers import pipeline | |
| from dotenv import load_dotenv | |
| import nltk | |
| # Load environment variables from .env file | |
| load_dotenv() | |
| hf_api_key = os.getenv("HUGGING_FACE_KEY") | |
| # Initialize Hugging Face Text Generation Pipeline | |
| llama_model = "meta-llama/Meta-Llama-3.1-8B-Instruct" | |
| text_generator = pipeline("text-generation", model=llama_model, use_auth_token=hf_api_key) | |
| # Load the TensorFlow model | |
| model = tf.keras.models.load_model("resume_generator_model.h5") | |
| # Define helper functions | |
| def enhance_with_huggingface(resume_text, job_title): | |
| """Generate enhanced resume content using Llama.""" | |
| prompt = f"Enhance the following resume for the job title '{job_title}': {resume_text}" | |
| response = text_generator(prompt, max_length=500, num_return_sequences=1) | |
| return response[0]['generated_text'] | |
| def enhance_with_local_model(resume_text, job_title): | |
| """Generate enhancements using local TensorFlow model.""" | |
| # Placeholder example: Use some custom logic for enhancement based on the local model. | |
| sample_input = np.array([[len(resume_text.split()), len(job_title.split())]]) | |
| enhancement_score = model.predict(sample_input) | |
| return f"Enhanced (Local Model) - Score: {enhancement_score[0][0]:.2f}" | |
| # Define the function to handle resume enhancements | |
| def enhance_resume(uploaded_resume, job_title): | |
| """Main enhancement function.""" | |
| # Extract text from the uploaded file | |
| resume_text = uploaded_resume.read().decode('utf-8') | |
| # Use both models for enhancements | |
| llama_enhanced_resume = enhance_with_huggingface(resume_text, job_title) | |
| local_enhanced_resume = enhance_with_local_model(resume_text, job_title) | |
| # Combine results from both models | |
| enhanced_resume = f"{llama_enhanced_resume}\n\n{local_enhanced_resume}" | |
| return enhanced_resume | |
| # Create a Gradio interface | |
| inputs = [ | |
| gr.inputs.File(label="Upload your Resume (TXT)", type="file"), | |
| gr.inputs.Textbox(label="Job Title", placeholder="e.g., Data Scientist"), | |
| ] | |
| outputs = gr.outputs.Textbox(label="Enhanced Resume") | |
| # Create a Gradio Interface | |
| app = gr.Interface( | |
| fn=enhance_resume, | |
| inputs=inputs, | |
| outputs=outputs, | |
| title="Resume Enhancer", | |
| description="Enhance your resume based on the given job title using AI models.", | |
| ) | |
| # Run the app | |
| if __name__ == "__main__": | |
| app.launch() | |