File size: 1,603 Bytes
8908602
2aafbf4
8908602
 
 
2aafbf4
8908602
0ee9995
2aafbf4
 
 
8908602
2aafbf4
 
 
 
 
 
 
 
8908602
2aafbf4
 
 
 
 
 
 
 
 
8908602
2aafbf4
 
 
 
 
8908602
2aafbf4
 
 
8908602
 
 
 
2aafbf4
8908602
2aafbf4
8908602
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
import gradio as gr
import joblib
from pytorch_tabnet.tab_model import TabNetClassifier

# Load model, scaler, and encoder
model = TabNetClassifier()
model.load_model('tabnet_model.zip')

scaler = joblib.load('D:/Dataset/IPIP-FFM-data-8Nov2018/scaler.save')
encoder = joblib.load('D:/Dataset/IPIP-FFM-data-8Nov2018/encoder.save')

# Full form trait mapping
trait_prefixes = {
    'Extraversion': 'EXT',
    'Emotional Stability': 'EST',
    'Agreeableness': 'AGR',
    'Conscientiousness': 'CSN',
    'Openness': 'OPN'
}

# Create full feature names with full form labels
feature_labels = []
feature_keys = []
for trait, abbrev in trait_prefixes.items():
    for i in range(10):
        feature_labels.append(f"{trait} Q{i+1}")
        feature_keys.append(f"{abbrev}{i+1}")

# Inference function
def predict_personality(*inputs):
    input_array = np.array(inputs).reshape(1, -1)
    scaled_input = scaler.transform(input_array)
    pred = model.predict(scaled_input)
    personality = encoder.inverse_transform(pred)[0]
    return f"Predicted Personality: **{personality}**"

# Gradio UI: 50 sliders with full trait names
inputs = [gr.Slider(1.0, 5.0, value=3.0, label=label) for label in feature_labels]
output = gr.Textbox(label="Prediction")

demo = gr.Interface(
    fn=predict_personality,
    inputs=inputs,
    outputs=output,
    title="Personality Type Classifier (Introvert vs. Extrovert)",
    description="Provide scores (1–5) for 50 questions from the IPIP-FFM questionnaire. The model will predict whether the person is an Introvert or an Extrovert."
)
demo.launch()