Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,32 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
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
|
7 |
|
8 |
-
#
|
9 |
-
|
|
|
|
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
# Placeholder logic: Assign random scores to traits
|
17 |
-
return {trait: round(random.uniform(0, 1), 2) for trait in traits}
|
18 |
|
19 |
-
#
|
20 |
if st.button("Predict Personality"):
|
21 |
if user_input.strip():
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
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
|
|
|
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.")
|