Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,19 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
-
from torch.nn import functional as F
|
4 |
-
import pandas as pd
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
if sentence and labels:
|
22 |
-
inputs = tokenizer.batch_encode_plus([sentence] + labels,
|
23 |
-
return_tensors='pt',
|
24 |
-
pad_to_max_length=True)
|
25 |
-
input_ids = inputs['input_ids']
|
26 |
-
attention_mask = inputs['attention_mask']
|
27 |
-
output = model(input_ids, attention_mask=attention_mask)[0]
|
28 |
-
sentence_rep = output[:1].mean(dim=1)
|
29 |
-
label_reps = output[1:].mean(dim=1)
|
30 |
-
|
31 |
-
similarities = F.cosine_similarity(sentence_rep, label_reps)
|
32 |
-
similarities = similarities.cpu().detach().numpy() # Convert to numpy array for easier handling
|
33 |
-
|
34 |
-
# Sorting indices for displaying in order
|
35 |
-
sorted_indices = similarities.argsort()[::-1]
|
36 |
-
sorted_labels = [labels[idx] for idx in sorted_indices]
|
37 |
-
sorted_similarities = similarities[sorted_indices]
|
38 |
-
|
39 |
-
# Display results in bar chart
|
40 |
-
df = pd.DataFrame({'Label': sorted_labels, 'Similarity': sorted_similarities})
|
41 |
-
st.bar_chart(df.set_index('Label'))
|
42 |
-
else:
|
43 |
-
st.error("Please enter both a sentence and some labels.")
|
|
|
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 |
+
labels = ["Peacemaker", "Loyalist", "Achiever", "Reformer", "Individualist", "Helper", "Challenger", "Investigator", "Enthusiast"]
|
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(resume_text, labels)
|
16 |
+
# Display the results
|
17 |
+
st.write("Predictions:")
|
18 |
+
for label, score in zip(result['labels'], result['scores']):
|
19 |
+
st.write(f"{label}: {score*100:.2f}%")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|