Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,62 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Set up the app title and description
|
| 5 |
-
st.
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Load the Hugging Face pre-trained model
|
| 9 |
@st.cache_resource
|
|
@@ -13,20 +66,21 @@ def load_model():
|
|
| 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 |
-
#
|
| 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("Analysis Results")
|
| 25 |
for result in results:
|
| 26 |
st.write(f"**Label:** {result['label']}, **Score:** {result['score']:.2f}")
|
|
|
|
| 27 |
else:
|
| 28 |
-
st.warning("Please enter some text to predict personality.")
|
| 29 |
|
| 30 |
# Footer
|
| 31 |
-
st.
|
| 32 |
-
st.write("This app uses a sentiment analysis model from Hugging Face to simulate personality prediction.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Set up the app title and description with custom styling
|
| 5 |
+
st.set_page_config(page_title="Personality Predictor", page_icon=":guardsman:", layout="wide")
|
| 6 |
+
|
| 7 |
+
# Apply custom CSS styles
|
| 8 |
+
st.markdown("""
|
| 9 |
+
<style>
|
| 10 |
+
.title {
|
| 11 |
+
font-size: 36px;
|
| 12 |
+
font-weight: bold;
|
| 13 |
+
color: #2C3E50;
|
| 14 |
+
text-align: center;
|
| 15 |
+
}
|
| 16 |
+
.description {
|
| 17 |
+
font-size: 20px;
|
| 18 |
+
color: #34495E;
|
| 19 |
+
text-align: center;
|
| 20 |
+
margin-bottom: 20px;
|
| 21 |
+
}
|
| 22 |
+
.input-area {
|
| 23 |
+
font-size: 18px;
|
| 24 |
+
padding: 15px;
|
| 25 |
+
border-radius: 8px;
|
| 26 |
+
border: 1px solid #BDC3C7;
|
| 27 |
+
background-color: #ECF0F1;
|
| 28 |
+
}
|
| 29 |
+
.btn {
|
| 30 |
+
background-color: #2980B9;
|
| 31 |
+
color: white;
|
| 32 |
+
font-size: 18px;
|
| 33 |
+
font-weight: bold;
|
| 34 |
+
border-radius: 8px;
|
| 35 |
+
padding: 10px 20px;
|
| 36 |
+
cursor: pointer;
|
| 37 |
+
}
|
| 38 |
+
.btn:hover {
|
| 39 |
+
background-color: #3498DB;
|
| 40 |
+
}
|
| 41 |
+
.result-card {
|
| 42 |
+
padding: 20px;
|
| 43 |
+
background-color: #F5F5F5;
|
| 44 |
+
border-radius: 8px;
|
| 45 |
+
border: 1px solid #BDC3C7;
|
| 46 |
+
margin-top: 30px;
|
| 47 |
+
}
|
| 48 |
+
.footer {
|
| 49 |
+
text-align: center;
|
| 50 |
+
margin-top: 40px;
|
| 51 |
+
color: #7F8C8D;
|
| 52 |
+
font-size: 14px;
|
| 53 |
+
}
|
| 54 |
+
</style>
|
| 55 |
+
""", unsafe_allow_html=True)
|
| 56 |
+
|
| 57 |
+
# Set up the app's title and description
|
| 58 |
+
st.markdown('<div class="title">Personality Predictor</div>', unsafe_allow_html=True)
|
| 59 |
+
st.markdown('<div class="description">Enter text to predict personality-related traits. This app analyzes text and provides insights into the sentiment.</div>', unsafe_allow_html=True)
|
| 60 |
|
| 61 |
# Load the Hugging Face pre-trained model
|
| 62 |
@st.cache_resource
|
|
|
|
| 66 |
# Initialize the model
|
| 67 |
classifier = load_model()
|
| 68 |
|
| 69 |
+
# Text input area with custom styling
|
| 70 |
+
user_input = st.text_area("Write something here:", placeholder="E.g., I enjoy social gatherings and meeting new people.", height=200, key="input_area", help="Type a sentence or paragraph describing a personality trait.", max_chars=500)
|
| 71 |
|
| 72 |
+
# Action button with custom style
|
| 73 |
+
if st.button("Predict Personality", key="predict_button", help="Click to predict the personality traits based on your input"):
|
| 74 |
if user_input.strip():
|
| 75 |
with st.spinner("Analyzing text..."):
|
| 76 |
results = classifier(user_input)
|
| 77 |
+
st.markdown('<div class="result-card">', unsafe_allow_html=True)
|
| 78 |
st.subheader("Analysis Results")
|
| 79 |
for result in results:
|
| 80 |
st.write(f"**Label:** {result['label']}, **Score:** {result['score']:.2f}")
|
| 81 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 82 |
else:
|
| 83 |
+
st.warning("Please enter some text to predict personality.", icon="⚠️")
|
| 84 |
|
| 85 |
# Footer
|
| 86 |
+
st.markdown('<div class="footer">This app uses sentiment analysis to simulate personality prediction. Developed with ❤️ for learning purposes.</div>', unsafe_allow_html=True)
|
|
|