Fralet commited on
Commit
a1a24b4
·
verified ·
1 Parent(s): 024802a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -17,13 +17,13 @@ classifier = pipeline("zero-shot-classification", model="Fralet/personality")
17
  st.title("Resume-based Personality Prediction by Serikov Ayanbek")
18
 
19
  # Load data from Excel
20
- data = pd.read_excel("ResponseTest.xlsx") # Replace 'your_excel_file.xlsx' with your actual file name
21
 
22
  # Preprocess text function
23
  def preprocess_text(text):
24
  text = re.sub(r'\W', ' ', str(text))
25
  text = text.lower()
26
- text is re.sub(r'\s+[a-z]\s+', ' ', text)
27
  text = re.sub(r'^[a-z]\s+', ' ', text)
28
  text = re.sub(r'\s+', ' ', text)
29
  stop_words = set(stopwords.words('english'))
@@ -41,13 +41,14 @@ data['processed_text'] = data['combined_text'].apply(preprocess_text)
41
  confidence_threshold = st.slider("Confidence Threshold", 0.0, 1.0, 0.5)
42
 
43
  if st.button("Predict Personality"):
44
- # Function to apply predictions using dynamic labels from MAX1, MAX2, MAX3
45
  def get_predictions(row):
46
  custom_labels = [row['MAX1'], row['MAX2'], row['MAX3']] # Get labels from each row
47
  processed_text = row['processed_text']
48
  result = classifier(processed_text, custom_labels)
49
- return result
 
50
 
51
  # Apply predictions across all rows
52
- data['predicted_labels'] = data.apply(get_predictions, axis=1)
53
- st.dataframe(data[['True_label', 'Predicted', 'predicted_labels']])
 
17
  st.title("Resume-based Personality Prediction by Serikov Ayanbek")
18
 
19
  # Load data from Excel
20
+ data = pd.read_excel("ResponseTest.xlsx") # Replace 'ResponseTest.xlsx' with your actual file name
21
 
22
  # Preprocess text function
23
  def preprocess_text(text):
24
  text = re.sub(r'\W', ' ', str(text))
25
  text = text.lower()
26
+ text = re.sub(r'\s+[a-z]\s+', ' ', text)
27
  text = re.sub(r'^[a-z]\s+', ' ', text)
28
  text = re.sub(r'\s+', ' ', text)
29
  stop_words = set(stopwords.words('english'))
 
41
  confidence_threshold = st.slider("Confidence Threshold", 0.0, 1.0, 0.5)
42
 
43
  if st.button("Predict Personality"):
44
+ # Function to apply predictions using dynamic labels from MAX1, MAX2, MAX3 and only return the highest scored label
45
  def get_predictions(row):
46
  custom_labels = [row['MAX1'], row['MAX2'], row['MAX3']] # Get labels from each row
47
  processed_text = row['processed_text']
48
  result = classifier(processed_text, custom_labels)
49
+ highest_score_label = result['labels'][0] # Assumes the labels are sorted by score, highest first
50
+ return highest_score_label
51
 
52
  # Apply predictions across all rows
53
+ data['Predicted'] = data.apply(get_predictions, axis=1)
54
+ st.dataframe(data[['True_label', 'Predicted']])