mdakhras commited on
Commit
9fd18ae
·
verified ·
1 Parent(s): f24dee8

Update src/streamlit_app.py

Browse files

removing cv upload input to text input

Files changed (1) hide show
  1. src/streamlit_app.py +10 -26
src/streamlit_app.py CHANGED
@@ -1,14 +1,13 @@
1
  import streamlit as st
2
  import fitz # PyMuPDF
3
  from dotenv import load_dotenv
4
- import io
5
  import os
6
  import requests
7
 
8
  # Load environment variables from .env file
9
  load_dotenv()
10
 
11
- # Check and set environment variables
12
  ENDPOINT = os.getenv("AZURE_OPENAI_ENDPOINT")
13
  API_KEY = os.getenv("AZURE_OPENAI_API_KEY")
14
  DEPLOYMENT_NAME = os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME")
@@ -30,18 +29,6 @@ headers = {
30
  "Authorization": f"Bearer {HuggingFace_API_KEY}" # Replace with your actual API key
31
  }
32
 
33
- # Function to extract text from the uploaded PDF
34
- def extract_text_from_pdf(pdf_file):
35
- # Read the uploaded file as a byte stream
36
- pdf_bytes = pdf_file.read()
37
-
38
- # Open the PDF from the byte stream
39
- doc = fitz.open("pdf", pdf_bytes) # Fix: use the correct format to open the byte stream
40
- text = ""
41
- for page in doc:
42
- text += page.get_text()
43
- return text
44
-
45
  # Function to extract relevant information from the CV using Hugging Face or Azure OpenAI
46
  def extract_info_from_openai(text):
47
  prompt = f"""
@@ -62,27 +49,24 @@ def extract_info_from_openai(text):
62
  # If the Hugging Face response is successful, extract the generated text
63
  if response.status_code == 200:
64
  result = response.json() # Parse the JSON response
65
- return result.get("generated_text", "Error: Unable to extract text.")
66
  else:
67
  return f"Error: {response.status_code} - {response.text}"
68
 
69
  # Streamlit App UI
70
  st.title("AI Screening")
71
- st.write("Upload a CV PDF file, and the app will extract relevant information such as job title, location, skills, experience, and education.")
72
-
73
- # File uploader
74
- uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
75
 
76
- if uploaded_file is not None:
77
- # Extract text from the uploaded PDF
78
- text = extract_text_from_pdf(uploaded_file)
79
 
80
- # Display the extracted text (optional)
81
- st.subheader("Extracted Text from CV")
82
- st.text_area("Text from CV", text, height=300)
 
83
 
84
  # Extract relevant information using Hugging Face (or Azure OpenAI if you need)
85
- extracted_info = extract_info_from_openai(text)
86
 
87
  # Display the extracted information
88
  st.subheader("Extracted Information")
 
1
  import streamlit as st
2
  import fitz # PyMuPDF
3
  from dotenv import load_dotenv
 
4
  import os
5
  import requests
6
 
7
  # Load environment variables from .env file
8
  load_dotenv()
9
 
10
+ # Set environment variables for Azure OpenAI
11
  ENDPOINT = os.getenv("AZURE_OPENAI_ENDPOINT")
12
  API_KEY = os.getenv("AZURE_OPENAI_API_KEY")
13
  DEPLOYMENT_NAME = os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME")
 
29
  "Authorization": f"Bearer {HuggingFace_API_KEY}" # Replace with your actual API key
30
  }
31
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  # Function to extract relevant information from the CV using Hugging Face or Azure OpenAI
33
  def extract_info_from_openai(text):
34
  prompt = f"""
 
49
  # If the Hugging Face response is successful, extract the generated text
50
  if response.status_code == 200:
51
  result = response.json() # Parse the JSON response
52
+ return result.get("generated_text", "Error: Unable to generate response.")
53
  else:
54
  return f"Error: {response.status_code} - {response.text}"
55
 
56
  # Streamlit App UI
57
  st.title("AI Screening")
58
+ st.write("Enter the CV text below, and the app will extract relevant information such as job title, location, skills, experience, and education.")
 
 
 
59
 
60
+ # Text area for entering CV content manually
61
+ cv_text = st.text_area("Enter CV Text", height=300)
 
62
 
63
+ if cv_text:
64
+ # Display the entered CV text
65
+ st.subheader("Entered Text from CV")
66
+ st.text_area("CV Text", cv_text, height=300)
67
 
68
  # Extract relevant information using Hugging Face (or Azure OpenAI if you need)
69
+ extracted_info = extract_info_from_openai(cv_text)
70
 
71
  # Display the extracted information
72
  st.subheader("Extracted Information")