Anshini commited on
Commit
01a0155
Β·
verified Β·
1 Parent(s): 965a6a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -25
app.py CHANGED
@@ -1,38 +1,49 @@
1
  import streamlit as st
2
  import os
3
  import tempfile
4
- import numpy as np
5
- import easyocr
6
-
7
- # Only needed if you're doing any OCR or OpenCV processing
8
- # import cv2
9
-
10
  from langchain.prompts import PromptTemplate
11
  from langchain.chains import LLMChain
12
  from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
13
 
14
- # Set page config
 
 
 
 
15
  st.set_page_config(page_title="Resume Validator", layout="centered", page_icon="πŸ“„")
16
- st.title("πŸ“„ AI Resume Validator")
17
- st.write("Upload your resume and get instant feedback on its quality and suggestions to improve.")
18
 
19
- # File uploader
20
- uploaded_file = st.file_uploader("Upload Resume (PDF or DOCX)", type=["pdf", "docx"])
 
 
 
 
 
 
 
 
21
 
22
- # Only run logic if a file is uploaded
23
  if uploaded_file:
24
- # Extract text based on file type
 
 
 
 
 
25
  if uploaded_file.name.endswith(".pdf"):
26
- from pdfminer.high_level import extract_text
27
- resume_text = extract_text(uploaded_file)
28
  else:
29
- import docx2txt
30
- resume_text = docx2txt.process(uploaded_file)
 
 
31
 
32
  st.markdown("### πŸ“ƒ Extracted Resume Text")
33
  st.code(resume_text)
34
 
35
- # Prompt template for evaluation
36
  template = """
37
  You are an expert HR recruiter.
38
 
@@ -51,23 +62,30 @@ if uploaded_file:
51
  - Weaknesses
52
  - Actionable suggestions to improve
53
  """
 
54
  prompt = PromptTemplate(input_variables=["resume_text"], template=template)
55
 
56
- # Initialize the model
57
  llm = HuggingFaceEndpoint(
58
  repo_id="mistralai/Mistral-7B-Instruct-v0.3",
59
  temperature=0.5,
60
- max_new_tokens=300,
61
  task="conversational"
62
  )
 
63
  model = ChatHuggingFace(llm=llm)
 
64
  chain = LLMChain(llm=model, prompt=prompt)
65
 
66
- # Analyze resume on button click
67
  if st.button("βœ… Validate Resume"):
68
  with st.spinner("Analyzing your resume..."):
69
- result = chain.run(resume_text=resume_text)
70
- st.markdown("### πŸ“Š Feedback")
71
- st.success(result)
 
 
 
 
 
72
  else:
73
- st.info("Please upload a resume file (PDF or DOCX) to start the validation.")
 
1
  import streamlit as st
2
  import os
3
  import tempfile
4
+ import docx2txt
5
+ from pdfminer.high_level import extract_text
 
 
 
 
6
  from langchain.prompts import PromptTemplate
7
  from langchain.chains import LLMChain
8
  from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
9
 
10
+ # Set your Hugging Face token via environment variable or secret management
11
+ os.environ["HUGGINGFACEHUB_API_KEY"] = os.getenv("HF")
12
+ os.environ["HF_TOKEN"] = os.getenv("HF")
13
+
14
+ # UI Configuration
15
  st.set_page_config(page_title="Resume Validator", layout="centered", page_icon="πŸ“„")
 
 
16
 
17
+ st.markdown("""
18
+ <h1 style='text-align: center;'>πŸ“„ AI Resume Validator</h1>
19
+ <p style='text-align: center;'>Upload your resume and receive instant feedback with suggestions for improvement</p>
20
+ <br>
21
+ """, unsafe_allow_html=True)
22
+
23
+ # File upload
24
+ uploaded_file = st.file_uploader("πŸ“€ Upload Resume (PDF or DOCX)", type=["pdf", "docx"])
25
+
26
+ resume_text = ""
27
 
 
28
  if uploaded_file:
29
+ # Save the uploaded file temporarily
30
+ with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[-1]) as tmp_file:
31
+ tmp_file.write(uploaded_file.read())
32
+ temp_path = tmp_file.name
33
+
34
+ # Extract text
35
  if uploaded_file.name.endswith(".pdf"):
36
+ resume_text = extract_text(temp_path)
 
37
  else:
38
+ resume_text = docx2txt.process(temp_path)
39
+
40
+ # Clean up temp file
41
+ os.remove(temp_path)
42
 
43
  st.markdown("### πŸ“ƒ Extracted Resume Text")
44
  st.code(resume_text)
45
 
46
+ # Prompt template
47
  template = """
48
  You are an expert HR recruiter.
49
 
 
62
  - Weaknesses
63
  - Actionable suggestions to improve
64
  """
65
+
66
  prompt = PromptTemplate(input_variables=["resume_text"], template=template)
67
 
68
+ # LLM Configuration
69
  llm = HuggingFaceEndpoint(
70
  repo_id="mistralai/Mistral-7B-Instruct-v0.3",
71
  temperature=0.5,
72
+ max_new_tokens=10,
73
  task="conversational"
74
  )
75
+
76
  model = ChatHuggingFace(llm=llm)
77
+
78
  chain = LLMChain(llm=model, prompt=prompt)
79
 
 
80
  if st.button("βœ… Validate Resume"):
81
  with st.spinner("Analyzing your resume..."):
82
+ try:
83
+ result = chain.run(resume_text=resume_text)
84
+ st.success("βœ… Resume Analysis Completed")
85
+ st.markdown("### πŸ“Š Feedback")
86
+ st.write(result)
87
+ except Exception as e:
88
+ st.error(f"⚠️ An error occurred: {e}")
89
+
90
  else:
91
+ st.markdown("<center><i>Please upload your resume to start validation.</i></center>", unsafe_allow_html=True)