mgbam commited on
Commit
5fdef64
·
verified ·
1 Parent(s): d068091

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -48
app.py CHANGED
@@ -1,65 +1,77 @@
1
- import os
2
  import gradio as gr
3
- import requests
 
4
  from dotenv import load_dotenv
5
 
 
6
  load_dotenv()
 
7
 
8
- BACKEND_URL = "http://127.0.0.1:5000/api" # Adjust if hosted elsewhere
 
9
 
 
10
  def generate_resume(name, email, phone, summary, experience, education, skills):
11
- payload = {
12
- "name": name,
13
- "email": email,
14
- "phone": phone,
15
- "summary": summary,
16
- "experience": experience,
17
- "education": education,
18
- "skills": skills
19
- }
20
- response = requests.post(f"{BACKEND_URL}/generate", json=payload)
21
- if response.status_code == 200:
22
- return response.json().get("resume", "")
23
- return f"Error: {response.text}"
24
-
25
- def score_resume(resume_text, job_description):
26
- payload = {
27
- "resume": resume_text,
28
- "job_description": job_description
29
- }
30
- response = requests.post(f"{BACKEND_URL}/score", json=payload)
31
- if response.status_code == 200:
32
- data = response.json()
33
- return f"Score: {data['score']}/100\nSuggestions:\n" + "\n".join(data['suggestions'])
34
- return f"Error: {response.text}"
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  def refine_section(section_text, instruction):
37
- payload = {
38
- "text": section_text,
39
- "instruction": instruction
40
- }
41
- response = requests.post(f"{BACKEND_URL}/refine_section", json=payload)
42
- if response.status_code == 200:
43
- return response.json().get("refined_text", "")
44
- return f"Error: {response.text}"
45
 
 
46
  with gr.Blocks() as demo:
47
- gr.Markdown("## 🤖 AI Resume Builder")
48
 
49
  with gr.Tab("1️⃣ Generate Resume"):
50
- with gr.Row():
51
- name = gr.Textbox(label="Name")
52
- email = gr.Textbox(label="Email")
53
- phone = gr.Textbox(label="Phone")
54
  summary = gr.Textbox(label="Professional Summary")
55
  experience = gr.Textbox(label="Experience")
56
  education = gr.Textbox(label="Education")
57
  skills = gr.Textbox(label="Skills")
58
  resume_output = gr.Textbox(label="Generated Resume", lines=15)
59
- generate_btn = gr.Button("Generate Full Resume")
60
 
61
  generate_btn.click(
62
- generate_resume,
63
  inputs=[name, email, phone, summary, experience, education, skills],
64
  outputs=resume_output
65
  )
@@ -67,26 +79,25 @@ with gr.Blocks() as demo:
67
  with gr.Tab("2️⃣ Score Resume Against Job"):
68
  resume_input = gr.Textbox(label="Your Resume", lines=10)
69
  job_desc = gr.Textbox(label="Job Description", lines=5)
70
- score_output = gr.Textbox(label="Job Match Score + Suggestions", lines=10)
71
  score_btn = gr.Button("Evaluate")
72
 
73
  score_btn.click(
74
- score_resume,
75
  inputs=[resume_input, job_desc],
76
  outputs=score_output
77
  )
78
 
79
  with gr.Tab("3️⃣ Refine Resume Section"):
80
  section_input = gr.Textbox(label="Resume Section", lines=5)
81
- instruction_input = gr.Textbox(label="Refinement Instruction (e.g., make it more concise)")
82
  refined_output = gr.Textbox(label="Refined Text", lines=5)
83
  refine_btn = gr.Button("Refine")
84
 
85
  refine_btn.click(
86
- refine_section,
87
  inputs=[section_input, instruction_input],
88
  outputs=refined_output
89
  )
90
 
91
- if __name__ == "__main__":
92
- demo.launch()
 
 
1
  import gradio as gr
2
+ import google.generativeai as genai
3
+ import os
4
  from dotenv import load_dotenv
5
 
6
+ # Load environment variable
7
  load_dotenv()
8
+ API_KEY = os.getenv("GEMINI_API_KEY")
9
 
10
+ genai.configure(api_key=API_KEY)
11
+ model = genai.GenerativeModel("gemini-pro")
12
 
13
+ # --- AI Functions ---
14
  def generate_resume(name, email, phone, summary, experience, education, skills):
15
+ prompt = f"""
16
+ Create a professional resume using the following details:
17
+
18
+ Name: {name}
19
+ Email: {email}
20
+ Phone: {phone}
21
+
22
+ Summary:
23
+ {summary}
24
+
25
+ Experience:
26
+ {experience}
27
+
28
+ Education:
29
+ {education}
30
+
31
+ Skills:
32
+ {skills}
33
+
34
+ Format it clearly and professionally.
35
+ """
36
+ response = model.generate_content(prompt)
37
+ return response.text
38
+
39
+ def score_resume(resume, job_desc):
40
+ prompt = f"""
41
+ Evaluate how well the following resume matches the job description below.
42
+ Return a match score out of 100 and specific, actionable suggestions to improve the resume.
43
+
44
+ Resume:
45
+ {resume}
46
+
47
+ Job Description:
48
+ {job_desc}
49
+ """
50
+ response = model.generate_content(prompt)
51
+ return response.text
52
 
53
  def refine_section(section_text, instruction):
54
+ prompt = f"Refine this section according to the instruction.\nInstruction: {instruction}\nText: {section_text}"
55
+ response = model.generate_content(prompt)
56
+ return response.text
 
 
 
 
 
57
 
58
+ # --- Gradio UI ---
59
  with gr.Blocks() as demo:
60
+ gr.Markdown("## 🤖 AI Resume Builder using Gemini")
61
 
62
  with gr.Tab("1️⃣ Generate Resume"):
63
+ name = gr.Textbox(label="Name")
64
+ email = gr.Textbox(label="Email")
65
+ phone = gr.Textbox(label="Phone")
 
66
  summary = gr.Textbox(label="Professional Summary")
67
  experience = gr.Textbox(label="Experience")
68
  education = gr.Textbox(label="Education")
69
  skills = gr.Textbox(label="Skills")
70
  resume_output = gr.Textbox(label="Generated Resume", lines=15)
71
+ generate_btn = gr.Button("Generate Resume")
72
 
73
  generate_btn.click(
74
+ fn=generate_resume,
75
  inputs=[name, email, phone, summary, experience, education, skills],
76
  outputs=resume_output
77
  )
 
79
  with gr.Tab("2️⃣ Score Resume Against Job"):
80
  resume_input = gr.Textbox(label="Your Resume", lines=10)
81
  job_desc = gr.Textbox(label="Job Description", lines=5)
82
+ score_output = gr.Textbox(label="Match Score & Suggestions", lines=10)
83
  score_btn = gr.Button("Evaluate")
84
 
85
  score_btn.click(
86
+ fn=score_resume,
87
  inputs=[resume_input, job_desc],
88
  outputs=score_output
89
  )
90
 
91
  with gr.Tab("3️⃣ Refine Resume Section"):
92
  section_input = gr.Textbox(label="Resume Section", lines=5)
93
+ instruction_input = gr.Textbox(label="Refinement Instruction")
94
  refined_output = gr.Textbox(label="Refined Text", lines=5)
95
  refine_btn = gr.Button("Refine")
96
 
97
  refine_btn.click(
98
+ fn=refine_section,
99
  inputs=[section_input, instruction_input],
100
  outputs=refined_output
101
  )
102
 
103
+ demo.launch()