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 @app.route('/') def index(): return render_template_string(''' Job Description Generator

Job Description Generator

Generated Job Description

''') # Endpoint to generate job description @app.route('/generate-job-description', methods=['POST']) 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)