muqeet1234 commited on
Commit
2931218
·
verified ·
1 Parent(s): 0342b2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -1,32 +1,32 @@
1
  import streamlit as st
2
- import random
3
 
4
  # Set up the app title and description
5
- st.title("Personality Predictor")
6
- st.write("Enter some text about yourself or someone else, and this app will predict personality traits based on the Big Five model.")
7
 
8
- # Text input area
9
- user_input = st.text_area("Write something here:", placeholder="E.g., I love meeting new people and trying new experiences.")
 
 
10
 
11
- # Placeholder for trait predictions
12
- traits = ["Extraversion", "Agreeableness", "Conscientiousness", "Neuroticism", "Openness"]
13
 
14
- # Simulated predictions (replace with model predictions later)
15
- def predict_personality(text):
16
- # Placeholder logic: Assign random scores to traits
17
- return {trait: round(random.uniform(0, 1), 2) for trait in traits}
18
 
19
- # Button to predict personality
20
  if st.button("Predict Personality"):
21
  if user_input.strip():
22
- # Call prediction function
23
- predictions = predict_personality(user_input)
24
- st.subheader("Predicted Personality Traits")
25
- for trait, score in predictions.items():
26
- st.write(f"**{trait}:** {score}")
27
  else:
28
  st.warning("Please enter some text to predict personality.")
29
 
30
  # Footer
31
  st.write("---")
32
- st.write("This app uses NLP to simulate personality prediction. Replace the logic with a trained model for real predictions.")
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
 
4
  # Set up the app title and description
5
+ st.title("Enhanced Personality Predictor")
6
+ st.write("Enter some text about yourself or someone else, and this app will predict personality traits based on NLP analysis.")
7
 
8
+ # Load the Hugging Face pre-trained model
9
+ @st.cache_resource
10
+ def load_model():
11
+ return pipeline("text-classification", model="your-huggingface-model-name")
12
 
13
+ # Initialize the model
14
+ classifier = load_model()
15
 
16
+ # Text input area
17
+ user_input = st.text_area("Write something here:", placeholder="E.g., I enjoy social gatherings and meeting new people.")
 
 
18
 
19
+ # Predict personality traits
20
  if st.button("Predict Personality"):
21
  if user_input.strip():
22
+ with st.spinner("Analyzing text..."):
23
+ results = classifier(user_input)
24
+ st.subheader("Predicted Personality Traits")
25
+ for result in results:
26
+ st.write(f"**{result['label']}:** {result['score']:.2f}")
27
  else:
28
  st.warning("Please enter some text to predict personality.")
29
 
30
  # Footer
31
  st.write("---")
32
+ st.write("This app uses a Hugging Face NLP model for personality prediction. Replace the placeholder model name with a real one for production use.")