avizard commited on
Commit
32fc8f1
1 Parent(s): 1e74f1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -28
app.py CHANGED
@@ -1,49 +1,53 @@
 
1
  import io
2
- from dotenv import load_dotenv
3
-
4
- load_dotenv()
5
-
6
  import streamlit as st
7
- import os
8
- from PIL import Image
9
- import pdf2image
10
  import base64
11
  import google.generativeai as genai
12
 
13
- genai.configure(api_key=os.getenv("API_KEY"))
 
 
 
 
 
14
 
15
  def get_gemini_response(input, pdf_content,prompt):
16
  model = genai.GenerativeModel('gemini-pro-vision')
17
  response = model.generate_content([input,pdf_content[0],prompt])
18
  return response.text
19
 
 
 
 
 
 
 
 
20
  def input_pdf_setup(upload_file):
 
21
  if upload_file is not None:
22
- images=pdf2image.convert_from_bytes(upload_file.read())
23
-
24
- first_page = images[0]
25
-
26
- img_byte_arr = io.BytesIO()
27
- first_page.save(img_byte_arr, format='JPEG')
28
- img_byte_arr = img_byte_arr.getvalue()
29
-
30
- pdf_parts = [
31
- {
32
- "mime_type": "image/jpeg",
33
- "data": base64.b64encode(img_byte_arr).decode()
34
- }
35
- ]
36
- return pdf_parts
37
  else:
38
- raise FileNotFoundError("No File uploaded")
39
 
 
40
  st.set_page_config(page_title="Resume Parser")
41
  st.header("Mock ATS")
42
- input_text = st.text_area("Paste the job description here: ",key="input")
 
 
43
  uploaded_file = st.file_uploader("Upload your resume (only PDFs are supported)...", type="pdf")
44
 
45
  if uploaded_file is not None:
46
- st.write("Resume uploaded successfully")
47
 
48
  submit1=st.button("Tell me about the resume")
49
 
@@ -78,5 +82,3 @@ elif submit2:
78
  st.write(response)
79
  else:
80
  st.write("Please uplaod the resume")
81
-
82
-
 
1
+ import os
2
  import io
 
 
 
 
3
  import streamlit as st
4
+ from dotenv import load_dotenv
5
+ import fitz # PyMuPDF
 
6
  import base64
7
  import google.generativeai as genai
8
 
9
+
10
+ # Load environment variables
11
+ load_dotenv()
12
+
13
+ # Configure your application, for example, with an API key for a service
14
+ # api_key = os.getenv("API_KEY")
15
 
16
  def get_gemini_response(input, pdf_content,prompt):
17
  model = genai.GenerativeModel('gemini-pro-vision')
18
  response = model.generate_content([input,pdf_content[0],prompt])
19
  return response.text
20
 
21
+ def extract_text_from_first_page(pdf_path):
22
+ """Extract text from the first page of a PDF file using PyMuPDF (fitz)."""
23
+ doc = fitz.open(pdf_path)
24
+ first_page_text = doc[0].get_text()
25
+ doc.close()
26
+ return first_page_text
27
+
28
  def input_pdf_setup(upload_file):
29
+ """Save uploaded file to disk and extract text from the first page."""
30
  if upload_file is not None:
31
+ # Save the uploaded PDF to a temporary file
32
+ with open("temp_uploaded.pdf", "wb") as f:
33
+ f.write(upload_file.getbuffer())
34
+
35
+ # Extract text from the first page
36
+ extracted_text = extract_text_from_first_page("temp_uploaded.pdf")
37
+ return extracted_text
 
 
 
 
 
 
 
 
38
  else:
39
+ raise FileNotFoundError("No File uploaded")
40
 
41
+ # Streamlit UI setup
42
  st.set_page_config(page_title="Resume Parser")
43
  st.header("Mock ATS")
44
+
45
+ # User inputs
46
+ input_text = st.text_area("Paste the job description here:", key="input")
47
  uploaded_file = st.file_uploader("Upload your resume (only PDFs are supported)...", type="pdf")
48
 
49
  if uploaded_file is not None:
50
+ st.write("Resume uploaded successfully.")
51
 
52
  submit1=st.button("Tell me about the resume")
53
 
 
82
  st.write(response)
83
  else:
84
  st.write("Please uplaod the resume")