Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,9 +7,10 @@ from langchain.prompts import PromptTemplate
|
|
| 7 |
from langchain.chains import LLMChain
|
| 8 |
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
# UI Configuration
|
| 15 |
st.set_page_config(page_title="Resume Validator", layout="centered", page_icon="π")
|
|
@@ -26,7 +27,6 @@ uploaded_file = st.file_uploader("π€ Upload Resume (PDF or DOCX)", type=["pdf"
|
|
| 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
|
|
@@ -37,11 +37,11 @@ if uploaded_file:
|
|
| 37 |
else:
|
| 38 |
resume_text = docx2txt.process(temp_path)
|
| 39 |
|
| 40 |
-
#
|
| 41 |
os.remove(temp_path)
|
| 42 |
|
| 43 |
st.markdown("### π Extracted Resume Text")
|
| 44 |
-
st.
|
| 45 |
|
| 46 |
# Prompt template
|
| 47 |
template = """
|
|
@@ -69,8 +69,8 @@ if uploaded_file:
|
|
| 69 |
llm = HuggingFaceEndpoint(
|
| 70 |
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 71 |
temperature=0.5,
|
| 72 |
-
max_new_tokens=
|
| 73 |
-
task="
|
| 74 |
)
|
| 75 |
|
| 76 |
model = ChatHuggingFace(llm=llm)
|
|
@@ -83,10 +83,8 @@ if uploaded_file:
|
|
| 83 |
result = chain.run(resume_text=resume_text)
|
| 84 |
st.success("β
Resume Analysis Completed")
|
| 85 |
st.markdown("### π Feedback")
|
| 86 |
-
st.
|
| 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)
|
| 92 |
-
|
|
|
|
| 7 |
from langchain.chains import LLMChain
|
| 8 |
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 9 |
|
| 10 |
+
# Handle Hugging Face token
|
| 11 |
+
hf_token = os.getenv("HF") # For local dev
|
| 12 |
+
if hf_token:
|
| 13 |
+
os.environ["HUGGINGFACEHUB_API_KEY"] = hf_token
|
| 14 |
|
| 15 |
# UI Configuration
|
| 16 |
st.set_page_config(page_title="Resume Validator", layout="centered", page_icon="π")
|
|
|
|
| 27 |
resume_text = ""
|
| 28 |
|
| 29 |
if uploaded_file:
|
|
|
|
| 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
|
|
|
|
| 37 |
else:
|
| 38 |
resume_text = docx2txt.process(temp_path)
|
| 39 |
|
| 40 |
+
# Remove temp file
|
| 41 |
os.remove(temp_path)
|
| 42 |
|
| 43 |
st.markdown("### π Extracted Resume Text")
|
| 44 |
+
st.text_area("Resume Text", resume_text, height=300)
|
| 45 |
|
| 46 |
# Prompt template
|
| 47 |
template = """
|
|
|
|
| 69 |
llm = HuggingFaceEndpoint(
|
| 70 |
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 71 |
temperature=0.5,
|
| 72 |
+
max_new_tokens=512,
|
| 73 |
+
task="text-generation"
|
| 74 |
)
|
| 75 |
|
| 76 |
model = ChatHuggingFace(llm=llm)
|
|
|
|
| 83 |
result = chain.run(resume_text=resume_text)
|
| 84 |
st.success("β
Resume Analysis Completed")
|
| 85 |
st.markdown("### π Feedback")
|
| 86 |
+
st.markdown(result)
|
| 87 |
except Exception as e:
|
| 88 |
st.error(f"β οΈ An error occurred: {e}")
|
|
|
|
| 89 |
else:
|
| 90 |
st.markdown("<center><i>Please upload your resume to start validation.</i></center>", unsafe_allow_html=True)
|
|
|