File size: 1,081 Bytes
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
import gradio as gr
import numpy as np
import joblib
from pytorch_tabnet.tab_model import TabNetClassifier

# Load model and preprocessing tools
model = TabNetClassifier()
model.load_model("tabnet_model.zip")
scaler = joblib.load("scaler.save")
encoder = joblib.load("encoder.save")

# Features used in the model
features = [f"{trait}{i}" for trait in ["EXT", "EST", "AGR", "CSN", "OPN"] for i in range(1, 11)]

def predict_personality(*inputs):
    X = np.array(inputs).reshape(1, -1).astype(np.float32)
    X_scaled = scaler.transform(X)
    y_pred = model.predict(X_scaled)
    label = encoder.inverse_transform(y_pred)[0]
    return f"Predicted Personality Type: {label}"

# Create Gradio interface
inputs = [gr.Slider(1, 5, step=0.1, label=f) for f in features]

demo = gr.Interface(
    fn=predict_personality,
    inputs=inputs,
    outputs=gr.Text(label="Personality Prediction"),
    title="Personality Type Classifier (Introvert vs. Extrovert)",
    description="This model predicts if a person is Introvert or Extrovert based on their IPIP-FFM scores."
)

demo.launch()