Samay42 commited on
Commit
c2cd46e
·
verified ·
1 Parent(s): 4f38286

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -21
app.py CHANGED
@@ -1,26 +1,35 @@
 
1
  import streamlit as st
2
- import google.generativeai as gemini_pro
3
  import pandas as pd
4
  from io import StringIO
 
5
 
6
- # Initialize Google Generative AI Gemini-pro model
7
- gemini_pro.initialize(api_key='YOUR_GOOGLE_API_KEY')
 
8
 
9
- def analyze_resume(resume_text):
10
- # Using the Gemini-pro model to analyze the resume
11
- response = gemini_pro.analyze_text(resume_text)
12
- return response
 
 
 
 
 
 
 
 
13
 
14
  def extract_skills(resume_text):
15
- # Extract skills from resume text
16
- response = gemini_pro.extract_entities(resume_text, entity_type='skills')
17
- skills = [entity['text'] for entity in response['entities']]
18
  return skills
19
 
20
  def match_job_description(resume_text, job_description):
21
- # Match resume with job description
22
- response = gemini_pro.compare_texts(resume_text, job_description)
23
- score = response['similarity_score']
24
  return score
25
 
26
  # Streamlit application layout
@@ -30,18 +39,14 @@ st.header('Upload Resume')
30
  uploaded_file = st.file_uploader('Choose a file', type=['pdf', 'docx', 'txt'])
31
 
32
  if uploaded_file is not None:
33
- # Extract text from uploaded file
34
- stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
35
- resume_text = stringio.read()
 
36
 
37
  st.subheader('Resume Text')
38
  st.write(resume_text)
39
 
40
- st.subheader('Analyze Resume')
41
- if st.button('Analyze'):
42
- analysis_result = analyze_resume(resume_text)
43
- st.write('Analysis Result:', analysis_result)
44
-
45
  st.subheader('Extract Skills')
46
  if st.button('Extract Skills'):
47
  skills = extract_skills(resume_text)
 
1
+ import os
2
  import streamlit as st
3
+ import google.generativeai as genai
4
  import pandas as pd
5
  from io import StringIO
6
+ import fitz # PyMuPDF
7
 
8
+ # Configure Google Generative AI
9
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
10
+ model = genai.GenerativeModel('gemini-1.5-flash')
11
 
12
+ def extract_text_from_pdf(file):
13
+ """Extract text from PDF."""
14
+ text = ""
15
+ doc = fitz.open(stream=file.read(), filetype="pdf")
16
+ for page in doc:
17
+ text += page.get_text()
18
+ return text
19
+
20
+ def get_gemini_response(prompt):
21
+ """Function to load Google Gemini model and provide queries as response."""
22
+ response = model.generate_content([prompt])
23
+ return response[0]['text'] # Adjust this line based on actual response structure
24
 
25
  def extract_skills(resume_text):
26
+ prompt = f"Extract the skills from the following resume:\n\n{resume_text}"
27
+ skills = get_gemini_response(prompt)
 
28
  return skills
29
 
30
  def match_job_description(resume_text, job_description):
31
+ prompt = f"Compare the following resume with the job description and provide a match score:\n\nResume:\n{resume_text}\n\nJob Description:\n{job_description}"
32
+ score = get_gemini_response(prompt)
 
33
  return score
34
 
35
  # Streamlit application layout
 
39
  uploaded_file = st.file_uploader('Choose a file', type=['pdf', 'docx', 'txt'])
40
 
41
  if uploaded_file is not None:
42
+ if uploaded_file.type == "application/pdf":
43
+ resume_text = extract_text_from_pdf(uploaded_file)
44
+ else:
45
+ resume_text = uploaded_file.getvalue().decode("utf-8")
46
 
47
  st.subheader('Resume Text')
48
  st.write(resume_text)
49
 
 
 
 
 
 
50
  st.subheader('Extract Skills')
51
  if st.button('Extract Skills'):
52
  skills = extract_skills(resume_text)