Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,53 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# Initialize the zero-shot classification pipeline
|
5 |
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
6 |
|
7 |
# Define the candidate labels according to the Enneagram types
|
8 |
-
|
9 |
|
10 |
# Streamlit interface
|
11 |
st.title("Resume-based Personality Prediction")
|
12 |
resume_text = st.text_area("Enter Resume Text Here", height=300)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
if st.button("Predict Personality"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
# Make prediction
|
15 |
-
result = classifier(
|
|
|
16 |
# Display the results
|
17 |
-
st.write("Predictions:")
|
|
|
18 |
for label, score in zip(result['labels'], result['scores']):
|
19 |
-
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
+
import re
|
4 |
+
from nltk.corpus import stopwords
|
5 |
+
from nltk.stem import WordNetLemmatizer
|
6 |
+
nltk.download('stopwords')
|
7 |
+
nltk.download('wordnet')
|
8 |
|
9 |
# Initialize the zero-shot classification pipeline
|
10 |
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
11 |
|
12 |
# Define the candidate labels according to the Enneagram types
|
13 |
+
default_labels = ["Peacemaker", "Loyalist", "Achiever", "Reformer", "Individualist", "Helper", "Challenger", "Investigator", "Enthusiast"]
|
14 |
|
15 |
# Streamlit interface
|
16 |
st.title("Resume-based Personality Prediction")
|
17 |
resume_text = st.text_area("Enter Resume Text Here", height=300)
|
18 |
+
|
19 |
+
# User-defined labels option
|
20 |
+
user_labels = st.text_input("Enter custom labels separated by comma (optional)")
|
21 |
+
labels = user_labels.split(',') if user_labels else default_labels
|
22 |
+
|
23 |
+
# Prediction confidence threshold
|
24 |
+
confidence_threshold = st.slider("Confidence Threshold", 0.0, 1.0, 0.5)
|
25 |
+
|
26 |
if st.button("Predict Personality"):
|
27 |
+
# Text Preprocessing
|
28 |
+
def preprocess_text(text):
|
29 |
+
text = re.sub(r'\W', ' ', str(text))
|
30 |
+
text = text.lower()
|
31 |
+
text = re.sub(r'\s+[a-z]\s+', ' ', text)
|
32 |
+
text = re.sub(r'^[a-z]\s+', ' ', text)
|
33 |
+
text = re.sub(r'\s+', ' ', text)
|
34 |
+
stop_words = set(stopwords.words('english'))
|
35 |
+
lemmatizer = WordNetLemmatizer()
|
36 |
+
tokens = text.split()
|
37 |
+
tokens = [lemmatizer.lemmatize(word) for word in tokens if word not in stop_words]
|
38 |
+
return ' '.join(tokens)
|
39 |
+
|
40 |
+
processed_text = preprocess_text(resume_text)
|
41 |
+
|
42 |
# Make prediction
|
43 |
+
result = classifier(processed_text, labels)
|
44 |
+
|
45 |
# Display the results
|
46 |
+
st.write("Predictions (above confidence threshold):")
|
47 |
+
displayed = False
|
48 |
for label, score in zip(result['labels'], result['scores']):
|
49 |
+
if score >= confidence_threshold:
|
50 |
+
st.write(f"{label}: {score*100:.2f}%")
|
51 |
+
displayed = True
|
52 |
+
if not displayed:
|
53 |
+
st.write("No predictions exceed the confidence threshold.")
|