syedabdullah32's picture
Create app.py
6439d0f
raw
history blame
2.99 kB
import streamlit as st
import re
import spacy
# Load the spaCy English model
nlp = spacy.load("en_core_web_sm")
def extract_entities(text):
# Using spaCy for Named Entity Recognition (NER) to extract names
doc = nlp(text)
names = [ent.text for ent in doc.ents if ent.label_ == "PERSON"]
# Using regex to find Pakistani phone numbers
phone_numbers = re.findall(r'\+\d{2,3}\d{9,12}\b', text)
# Using regex to find emails
emails = re.findall(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b', text)
return names, phone_numbers, emails
def display_extracted_info(names, phone_numbers, emails):
if names:
st.subheader("πŸ‘€ Extracted Names:")
for name in names:
st.write(f"- {name}")
else:
st.info("No names found.")
if phone_numbers:
st.subheader("πŸ“ž Extracted Pakistani Phone Numbers:")
for phone in phone_numbers:
st.write(f"- {phone}")
else:
st.info("No Pakistani phone numbers found.")
if emails:
st.subheader("βœ‰οΈ Extracted Emails:")
for email in emails:
st.write(f"- {email}")
else:
st.info("No emails found.")
def main():
st.title("πŸ” Resume Information Extractor")
apply_custom_styles()
st.write("Enter resume text below to extract information.")
input_text = st.text_area("Paste your resume text here:", height=200)
if st.button("Extract"):
if input_text:
st.markdown("---")
st.header("πŸ“„ Extracted Information")
names, phone_numbers, emails = extract_entities(input_text)
display_extracted_info(names, phone_numbers, emails)
else:
st.warning("Please enter some text to extract entities.")
# Add a "Clear" button to reset the input text area
if st.button("Clear"):
st.text_area("Paste your resume text here:", value="", height=200)
def apply_custom_styles():
st.markdown(
"""
<style>
body {
background-color: #f5f5f5; /* Light gray background */
color: #333333; /* Dark gray text */
}
.stTextInput textarea {
background-color: #ffffff; /* White text area */
color: #333333; /* Dark gray text in text area */
border: 2px solid #d9d9d9; /* Light gray border */
}
.stButton button {
background-color: #F16623; /* Orange button */
color: #ffffff; /* White text on the button */
}
.stButton button:hover {
background-color: #e55c1e; /* Darker orange on hover */
}
.st-info {
background-color: #e6f7ff; /* Light blue info box */
color: #004085; /* Dark blue text in info box */
border: 1px solid #b8daff; /* Light blue border */
}
</style>
""",
unsafe_allow_html=True,
)
if __name__ == "__main__":
main()