File size: 1,055 Bytes
d381b23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

# Load the model and tokenizer
model_name = "KevSun/Personality_LM"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

# Function to predict personality traits
def predict_personality(text):
    inputs = tokenizer(text, return_tensors="pt")
    outputs = model(**inputs)
    probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
    labels = ["Introverted", "Extroverted", "Open", "Agreeable", "Conscientious", "Neurotic"]
    predictions = {label: prob.item() for label, prob in zip(labels, probs[0])}
    return predictions

# Create the Gradio interface
interface = gr.Interface(
    fn=predict_personality,
    inputs=gr.Textbox(lines=2, placeholder="Enter a sentence here..."),
    outputs=gr.Label(),
    title="Personality Analyzer",
    description="Enter a sentence and get a prediction of personality traits."
)

# Launch the Gradio app
interface.launch()