import gradio as gr import os from openai import OpenAI # Set your OpenAI API key client = OpenAI(api_key=os.environ['OPENAI_API_KEY']) jd_summary_global = "" # Global variable to store the job description summary def process_jd(text): global jd_summary_global # Declare the global variable if not text.strip(): # Check if the text is empty or contains only whitespace jd_summary_global = "No JD" # Update the global variable return "No JD" try: # Structuring a prompt to ask GPT-3.5 to summarize the job description prompt = f"Summarize the following job description into its job nature, responsibilities, and requirements:\n\n{text}" # Uploading text to OpenAI response = client.chat.completions.create(model="gpt-3.5-turbo", messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt}]) jd_summary = response.choices[0].message.content.strip() jd_summary_global = jd_summary # Update the global variable return jd_summary except Exception as e: return str(e) def cv_rating(cv_data): global jd_summary_global # Declare the global variable global cv_rating_global if len(jd_summary_global) <= 1 or jd_summary_global == "No JD": return "No JD in the previous tab." if len(cv_data) <= 1: return "No CV data" try: # Construct a prompt to ask GPT-3.5 to rate the CV based on the job description summary prompt = f""" Job Description Summary: {jd_summary_global} CV Data: {cv_data} Rate the compatibility of the CV with the job description and provide strengths, weaknesses, and recommendations to strengthen the CV. """ # Uploading text to OpenAI response = client.chat.completions.create(model="gpt-3.5-turbo", messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt}]) cv_rating_global= response.choices[0].message.content.strip() return cv_rating_global except Exception as e: return str(e) def create_cover_letter(additional_info): global jd_summary_global # Declare the global variable global cv_rating_global if len(jd_summary_global) <= 1 or jd_summary_global == "No JD": return "No JD in the previous tab." if len(cv_rating_global) <= 1: return "No CV data" try: # Constructing a prompt for GPT-3.5 to create a tailored cover letter prompt = f""" Job Description: {jd_summary_global} CV Data: {cv_rating_global} Additional Information: {additional_info} Create a tailored cover letter based on the job description and CV data provided: """ # Uploading text to OpenAI response = client.chat.completions.create(model="gpt-3.5-turbo", messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt}]) return response.choices[0].message.content.strip() except Exception as e: return str(e) def interview_qa(additional_info): global cv_rating_global if len(cv_rating_global) <= 1: return "No CV data" try: # Constructing a prompt for GPT-3.5 to create interview questions and answers prompt = f""" CV Data: {cv_rating_global} Additional Information: {additional_info} Generate at least 10 interview questions and provide potential answers based on the CV data and additional information provided: """ # Uploading text to OpenAI response = client.chat.completions.create(model="gpt-3.5-turbo", messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt}]) return response.choices[0].message.content.strip() except Exception as e: return str(e) def suggest_cv_content(additional_info): global jd_summary_global # Accessing the global variable for job description summary global cv_rating_global # Accessing the global variable for CV data if len(jd_summary_global) <= 1 or jd_summary_global == "No JD": return "No JD in the previous tab." if len(cv_rating_global) <= 1: return "No CV data" try: # Constructing a prompt for GPT-3.5 to suggest tailored CV content prompt = f""" Given the following job description, generate a new CV to better match the job description. Also, ensure the suggestions are formatted in a way that is compatible with most ATS solutions. Job Description: {jd_summary_global} CV Data: {cv_rating_global} Additional Information: {additional_info} """ # Uploading text to OpenAI response = client.chat.completions.create(model="gpt-3.5-turbo", messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt}] ) return response.choices[0].message.content.strip() except Exception as e: return str(e) jd_sum = gr.Interface( fn=process_jd, # function to process the text inputs=gr.Textbox(lines=30, label="Job Description"), outputs=gr.Textbox(lines=30, label="JD Summary", show_copy_button=True), live=False, title="Job Description Summarizer", description="An app to summarize job descriptions into job nature, responsibilities, and requirements. \ For more info, check out: https://github.com/jmesplana/BespokeCV", api_name="jd_sum" ) cv_rate_interface = gr.Interface( fn=cv_rating, inputs=gr.Textbox(lines=30, label="CV Data", placeholder="Paste the CV data here"), outputs=gr.Textbox(lines=30, label="ATS Rating System", show_copy_button=True), live=False, title="CV Rating", description="An app to rate CV compatibility with job description, providing strengths, weaknesses, and recommendations.", api_name="cv_rate_interface" ) cover_letter_interface = gr.Interface( fn=create_cover_letter, inputs=[gr.Textbox(lines=10, label="Additional Information", placeholder="Add any additional information or preferences for your cover letter here")], outputs=gr.Textbox(lines=30, label="Output", show_copy_button=True), live=False, title="Cover Letter Creator", description="An app to create a tailored cover letter based on job description and CV data. You may input additional information in the additional information box to add highlight specific experiences/projects and/or skills.", api_name="cover_letter_interface" ) interview_qa_interface = gr.Interface( fn=interview_qa, inputs=[gr.Textbox(lines=10, label="Additional Information", placeholder="Add any specific questions or additional information here")], outputs=gr.Textbox(lines=30, label="Output", show_copy_button=True), live=False, title="Interview Q&A", description="An app to generate interview questions and answers based on CV data and additional information.", api_name="interview_qa" ) cv_suggestion_interface = gr.Interface( fn=suggest_cv_content, inputs=[gr.Textbox(lines=10, label="Additional Information", placeholder="Add any specific requests or additional information here")], outputs=gr.Textbox(lines=30, label="Output", show_copy_button=True), live=False, title="CV Content Suggestion", description="An app to suggest CV content tailored to the job description, optimized for ATS compatibility.", api_name="cv_suggestion" ) bespokecv = gr.TabbedInterface([jd_sum, cv_rate_interface,cover_letter_interface,interview_qa_interface,cv_suggestion_interface], tab_names=['Job Description Summarizer','CV ATS Rating','Cover Letter Generator','Interview Q&A','Suggested CV']) if __name__ == "__main__": bespokecv.launch(share=True)