Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import requests
|
5 |
+
|
6 |
+
# Replace 'YOUR_GEMINI_API_KEY' with your actual Gemini API key.
|
7 |
+
GEMINI_API_KEY = "AIzaSyB05WLxtH1x4fMvB87M-GggjQlBnm3YWeE"
|
8 |
+
|
9 |
+
# This function sends the resume and job description to the Gemini API
|
10 |
+
# and returns an optimized resume tailored to the job description.
|
11 |
+
def optimize_resume(resume, job_description):
|
12 |
+
# Gemini API endpoint for text generation (update if needed)
|
13 |
+
url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent"
|
14 |
+
|
15 |
+
# Prepare the prompt for the AI model
|
16 |
+
prompt = (
|
17 |
+
"You are a professional resume writer. "
|
18 |
+
"Given the following resume and job description, rewrite the resume to be optimized for the job. "
|
19 |
+
"Keep the formatting clear and professional. "
|
20 |
+
"Only output the improved resume.\n\n"
|
21 |
+
f"Resume:\n{resume}\n\n"
|
22 |
+
f"Job Description:\n{job_description}\n"
|
23 |
+
)
|
24 |
+
|
25 |
+
# Prepare the request payload for Gemini API
|
26 |
+
data = {
|
27 |
+
"contents": [
|
28 |
+
{
|
29 |
+
"parts": [
|
30 |
+
{"text": prompt}
|
31 |
+
]
|
32 |
+
}
|
33 |
+
]
|
34 |
+
}
|
35 |
+
|
36 |
+
# Set the headers, including the API key for authentication
|
37 |
+
headers = {
|
38 |
+
"Content-Type": "application/json",
|
39 |
+
"x-goog-api-key": GEMINI_API_KEY
|
40 |
+
}
|
41 |
+
|
42 |
+
# Send the POST request to Gemini API
|
43 |
+
response = requests.post(url, headers=headers, json=data)
|
44 |
+
|
45 |
+
# If the request is successful, extract and return the optimized resume
|
46 |
+
if response.status_code == 200:
|
47 |
+
result = response.json()
|
48 |
+
# Extract the generated text from the response
|
49 |
+
try:
|
50 |
+
optimized_resume = result["candidates"][0]["content"]["parts"][0]["text"]
|
51 |
+
return optimized_resume
|
52 |
+
except (KeyError, IndexError):
|
53 |
+
return "Error: Unexpected response format from Gemini API."
|
54 |
+
else:
|
55 |
+
# If there's an error, return the error message
|
56 |
+
return f"Error: {response.status_code} - {response.text}"
|
57 |
+
|
58 |
+
# Create the Gradio interface
|
59 |
+
with gr.Blocks() as demo:
|
60 |
+
gr.Markdown(
|
61 |
+
"""
|
62 |
+
# AI Resume Optimizer
|
63 |
+
Paste your resume and the job description below.
|
64 |
+
The AI will rewrite your resume to better match the job!
|
65 |
+
"""
|
66 |
+
)
|
67 |
+
|
68 |
+
# Input for the user's resume
|
69 |
+
resume_input = gr.Textbox(
|
70 |
+
label="Paste your Resume",
|
71 |
+
lines=15,
|
72 |
+
placeholder="Paste your resume here..."
|
73 |
+
)
|
74 |
+
|
75 |
+
# Input for the job description
|
76 |
+
job_desc_input = gr.Textbox(
|
77 |
+
label="Paste the Job Description",
|
78 |
+
lines=10,
|
79 |
+
placeholder="Paste the job description here..."
|
80 |
+
)
|
81 |
+
|
82 |
+
# Output box for the optimized resume
|
83 |
+
optimized_resume_output = gr.Textbox(
|
84 |
+
label="Optimized Resume",
|
85 |
+
lines=15
|
86 |
+
)
|
87 |
+
|
88 |
+
# Button to submit the inputs and get the optimized resume
|
89 |
+
submit_btn = gr.Button("Optimize Resume")
|
90 |
+
|
91 |
+
# When the button is clicked, call the optimize_resume function
|
92 |
+
submit_btn.click(
|
93 |
+
fn=optimize_resume,
|
94 |
+
inputs=[resume_input, job_desc_input],
|
95 |
+
outputs=optimized_resume_output
|
96 |
+
)
|
97 |
+
|
98 |
+
# Run the Gradio app
|
99 |
+
if __name__ == "__main__":
|
100 |
+
demo.launch()
|