# app.py import gradio as gr import requests # Replace 'YOUR_GEMINI_API_KEY' with your actual Gemini API key. GEMINI_API_KEY = "AIzaSyB05WLxtH1x4fMvB87M-GggjQlBnm3YWeE" # This function sends the resume and job description to the Gemini API # and returns an optimized resume tailored to the job description. def optimize_resume(resume, job_description): # Gemini API endpoint for text generation (update if needed) url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent" # Prepare the prompt for the AI model prompt = ( "You are a professional resume writer. " "Given the following resume and job description, rewrite the resume to be optimized for the job. " "Keep the formatting clear and professional. " "Only output the improved resume.\n\n" f"Resume:\n{resume}\n\n" f"Job Description:\n{job_description}\n" ) # Prepare the request payload for Gemini API data = { "contents": [ { "parts": [ {"text": prompt} ] } ] } # Set the headers, including the API key for authentication headers = { "Content-Type": "application/json", "x-goog-api-key": GEMINI_API_KEY } # Send the POST request to Gemini API response = requests.post(url, headers=headers, json=data) # If the request is successful, extract and return the optimized resume if response.status_code == 200: result = response.json() # Extract the generated text from the response try: optimized_resume = result["candidates"][0]["content"]["parts"][0]["text"] return optimized_resume except (KeyError, IndexError): return "Error: Unexpected response format from Gemini API." else: # If there's an error, return the error message return f"Error: {response.status_code} - {response.text}" # Create the Gradio interface with gr.Blocks() as demo: gr.Markdown( """ # AI Resume Optimizer Paste your resume and the job description below. The AI will rewrite your resume to better match the job! """ ) # Input for the user's resume resume_input = gr.Textbox( label="Paste your Resume", lines=15, placeholder="Paste your resume here..." ) # Input for the job description job_desc_input = gr.Textbox( label="Paste the Job Description", lines=10, placeholder="Paste the job description here..." ) # Output box for the optimized resume optimized_resume_output = gr.Textbox( label="Optimized Resume", lines=15 ) # Button to submit the inputs and get the optimized resume submit_btn = gr.Button("Optimize Resume") # When the button is clicked, call the optimize_resume function submit_btn.click( fn=optimize_resume, inputs=[resume_input, job_desc_input], outputs=optimized_resume_output ) # Run the Gradio app if __name__ == "__main__": demo.launch()