Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -67,7 +67,7 @@ predict_and_log(data_open, 'Predicted_M', 'processed_text_mopen', true_label_col
|
|
67 |
|
68 |
# Optionally display a confirmation message
|
69 |
st.write("Predictions have been logged. Check your logs for details.")
|
70 |
-
|
71 |
import streamlit as st
|
72 |
import pandas as pd
|
73 |
import seaborn as sns
|
@@ -141,3 +141,58 @@ st.write("Distribution for Predicted_F")
|
|
141 |
plot_predictions_distribution(data, 'Predicted_F_encoded', 'Distribution of Predictions for Female Demographic')
|
142 |
st.write("Distribution for Predicted_M")
|
143 |
plot_predictions_distribution(data, 'Predicted_M_encoded', 'Distribution of Predictions for Male Demographic')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
# Optionally display a confirmation message
|
69 |
st.write("Predictions have been logged. Check your logs for details.")
|
70 |
+
|
71 |
import streamlit as st
|
72 |
import pandas as pd
|
73 |
import seaborn as sns
|
|
|
141 |
plot_predictions_distribution(data, 'Predicted_F_encoded', 'Distribution of Predictions for Female Demographic')
|
142 |
st.write("Distribution for Predicted_M")
|
143 |
plot_predictions_distribution(data, 'Predicted_M_encoded', 'Distribution of Predictions for Male Demographic')
|
144 |
+
"""
|
145 |
+
import streamlit as st
|
146 |
+
from transformers import pipeline
|
147 |
+
import re
|
148 |
+
import nltk
|
149 |
+
from nltk.corpus import stopwords
|
150 |
+
from nltk.stem import WordNetLemmatizer
|
151 |
+
nltk.download('stopwords')
|
152 |
+
nltk.download('wordnet')
|
153 |
+
|
154 |
+
# Initialize the zero-shot classification pipeline
|
155 |
+
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
156 |
+
|
157 |
+
# Define the candidate labels according to the Enneagram types
|
158 |
+
default_labels = ["Peacemaker", "Loyalist", "Achiever", "Reformer", "Individualist", "Helper", "Challenger", "Investigator", "Enthusiast"]
|
159 |
+
|
160 |
+
# Streamlit interface
|
161 |
+
st.title("Resume-based Personality Prediction")
|
162 |
+
resume_text = st.text_area("Enter Resume Text Here", height=300)
|
163 |
+
|
164 |
+
# User-defined labels option
|
165 |
+
user_labels = st.text_input("Enter custom labels separated by comma (optional)")
|
166 |
+
labels = user_labels.split(',') if user_labels else default_labels
|
167 |
+
|
168 |
+
# Prediction confidence threshold
|
169 |
+
confidence_threshold = st.slider("Confidence Threshold", 0.0, 1.0, 0.5)
|
170 |
+
|
171 |
+
if st.button("Predict Personality"):
|
172 |
+
# Text Preprocessing
|
173 |
+
def preprocess_text(text):
|
174 |
+
text = re.sub(r'\W', ' ', str(text))
|
175 |
+
text = text.lower()
|
176 |
+
text = re.sub(r'\s+[a-z]\s+', ' ', text)
|
177 |
+
text = re.sub(r'^[a-z]\s+', ' ', text)
|
178 |
+
text = re.sub(r'\s+', ' ', text)
|
179 |
+
stop_words = set(stopwords.words('english'))
|
180 |
+
lemmatizer = WordNetLemmatizer()
|
181 |
+
tokens = text.split()
|
182 |
+
tokens = [lemmatizer.lemmatize(word) for word in tokens if word not in stop_words]
|
183 |
+
return ' '.join(tokens)
|
184 |
+
|
185 |
+
processed_text = preprocess_text(resume_text)
|
186 |
+
|
187 |
+
# Make prediction
|
188 |
+
result = classifier(processed_text, labels)
|
189 |
+
|
190 |
+
# Display the results
|
191 |
+
st.write("Predictions (above confidence threshold):")
|
192 |
+
displayed = False
|
193 |
+
for label, score in zip(result['labels'], result['scores']):
|
194 |
+
if score >= confidence_threshold:
|
195 |
+
st.write(f"{label}: {score*100:.2f}%")
|
196 |
+
displayed = True
|
197 |
+
if not displayed:
|
198 |
+
st.write("No predictions exceed the confidence threshold.")
|