Download app.py from lokeshnaik33339/Job_Description: direct link, hf CLI and curl.
- Browser
- Download file 7.58 kB
-
https://huggingface.co/lokeshnaik33339/Job_Description/resolve/main/app.py
- Command line
-
hf download hf://lokeshnaik33339/Job_Description/app.py
-
curl -L -o app.py https://huggingface.co/lokeshnaik33339/Job_Description/resolve/main/app.py
7.58 kB
| from flask import Flask, jsonify, request, render_template_string | |
| import google.generativeai as genai | |
| import logging | |
| app = Flask(__name__) | |
| # Configure logging | |
| logging.basicConfig(level=logging.DEBUG) | |
| # Configure the API key for google-generativeai | |
| genai.configure(api_key="AIzaSyCpW-_Yqx2t4By_ZUpjiwVKEbQGAuAI8Sk") | |
| # Define the Generative Model | |
| model = genai.GenerativeModel('gemini-1.5-flash') | |
| # Route to display the HTML form | |
| def index(): | |
| return render_template_string(''' | |
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>Job Description Generator</title> | |
| <style> | |
| body { | |
| font-family: 'Roboto', sans-serif; | |
| background-color: #f0f2f5; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| height: 100vh; | |
| margin: 0; | |
| } | |
| .container { | |
| background: white; | |
| padding: 30px; | |
| box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | |
| border-radius: 10px; | |
| width: 100%; | |
| max-width: 450px; | |
| text-align: center; | |
| } | |
| h1 { | |
| color: #333; | |
| margin-bottom: 20px; | |
| } | |
| label { | |
| display: block; | |
| color: #666; | |
| margin-bottom: 5px; | |
| text-align: left; | |
| } | |
| input[type="text"], select { | |
| width: 100%; | |
| padding: 10px; | |
| margin: 5px 0 20px; | |
| border: 1px solid #ccc; | |
| border-radius: 5px; | |
| box-sizing: border-box; | |
| } | |
| input[type="submit"] { | |
| width: 100%; | |
| background-color: #007bff; | |
| color: white; | |
| padding: 10px; | |
| border: none; | |
| border-radius: 5px; | |
| cursor: pointer; | |
| font-size: 16px; | |
| } | |
| input[type="submit"]:hover { | |
| background-color: #0056b3; | |
| } | |
| #output { | |
| margin-top: 20px; | |
| padding: 20px; | |
| background-color: #f9f9f9; | |
| border: 1px solid #ddd; | |
| border-radius: 5px; | |
| display: none; | |
| text-align: left; | |
| } | |
| </style> | |
| <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <h1>Job Description Generator</h1> | |
| <form id="jobForm"> | |
| <label for="job_title">Job Title:</label> | |
| <input type="text" id="job_title" name="job_title" value="Data Scientist"> | |
| <label for="experience">Experience (years):</label> | |
| <input type="text" id="experience" name="experience" value="1+"> | |
| <label for="skills">Skills (comma separated):</label> | |
| <input type="text" id="skills" name="skills" value="Data Analysis, Statistical Analysis, Machine Learning, Data Visualization, Problem Solving, Communication"> | |
| <label for="technology">Technology (comma separated):</label> | |
| <input type="text" id="technology" name="technology" value="Python, R, SQL, TensorFlow, Keras, Pandas, NumPy, Scikit-Learn, Matplotlib, Seaborn"> | |
| <label for="non_technical_skills">Non-Technical Skills (comma separated):</label> | |
| <input type="text" id="non_technical_skills" name="non_technical_skills" value="Teamwork, Leadership, Time Management"> | |
| <label for="job_type">Job Type:</label> | |
| <select id="job_type" name="job_type"> | |
| <option value="Full-Time">Full-Time</option> | |
| <option value="Part-Time">Part-Time</option> | |
| <option value="Internship">Internship</option> | |
| </select> | |
| <label for="salary">Salary:</label> | |
| <input type="text" id="salary" name="salary" value="Competitive"> | |
| <input type="submit" value="Generate"> | |
| </form> | |
| <div id="output"> | |
| <h2>Generated Job Description</h2> | |
| <p id="jobDescription"></p> | |
| </div> | |
| </div> | |
| <script> | |
| $(document).ready(function() { | |
| $('#jobForm').on('submit', function(event) { | |
| event.preventDefault(); | |
| $.ajax({ | |
| url: '/generate-job-description', | |
| method: 'POST', | |
| data: $(this).serialize(), | |
| success: function(response) { | |
| $('#jobDescription').text(response.job_description); | |
| $('#output').show(); | |
| }, | |
| error: function(xhr, status, error) { | |
| $('#jobDescription').text('An error occurred: ' + error); | |
| $('#output').show(); | |
| } | |
| }); | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> | |
| ''') | |
| # Endpoint to generate job description | |
| def generate_job_description(): | |
| try: | |
| # Get the job title, experience, skills, technology, non-technical skills, job type, and salary from the form submission | |
| job_title = request.form['job_title'] | |
| experience = request.form['experience'] | |
| skills = request.form['skills'] | |
| technology = request.form['technology'] | |
| non_technical_skills = request.form['non_technical_skills'] | |
| job_type = request.form['job_type'] | |
| salary = request.form['salary'] | |
| # Create a prompt with the provided details | |
| prompt = (f"write job description for {job_title} with {experience} years of experience. " | |
| f"Skills required: {skills}. Technologies: {technology}. " | |
| f"Non-technical skills: {non_technical_skills}. Job type: {job_type}. " | |
| f"Salary: {salary}. " | |
| "The job description should be concise, professional, and free from questions or unnecessary punctuation marks like '*', '/n'.") | |
| # Generate the job description | |
| response = model.generate_content(prompt) | |
| # Extract the text from the response and clean it | |
| job_description = response.text.replace('*/n', '').replace('*', '').replace('\n', '\n') | |
| return jsonify({ | |
| 'job_description': job_description | |
| }) | |
| except Exception as e: | |
| logging.error(f"An error occurred: {e}") | |
| return jsonify({ | |
| 'error': str(e) | |
| }), 500 | |
| if __name__ == '__main__': | |
| app.run(host="0.0.0.0", port=7860) | |
| # app.run(debug=True) | |