Rahul-8853 commited on
Commit
916d6d2
·
verified ·
1 Parent(s): 354b43f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+ import torch
4
+
5
+ # Load the model and tokenizer from Hugging Face
6
+ model_name = "KevSun/Personality_LM"
7
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
9
+
10
+ # Streamlit app
11
+ st.title("Personality Prediction App")
12
+ st.write("Enter your text below to predict personality traits:")
13
+
14
+ # Input text from user
15
+ user_input = st.text_area("Your text here:")
16
+
17
+ if st.button("Predict"):
18
+ if user_input:
19
+ # Tokenize input text
20
+ inputs = tokenizer(user_input, return_tensors="pt")
21
+
22
+ # Get predictions from the model
23
+ with torch.no_grad():
24
+ outputs = model(**inputs)
25
+
26
+ # Extract the predictions
27
+ predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
28
+ predictions = predictions[0].tolist()
29
+
30
+ # Display the predictions
31
+ labels = ["Extraversion", "Agreeableness", "Conscientiousness", "Neuroticism", "Openness"]
32
+ for label, score in zip(labels, predictions):
33
+ st.write(f"{label}: {score:.4f}")
34
+ else:
35
+ st.write("Please enter some text to get predictions.")