MoinulwithAI commited on
Commit
8908602
·
verified ·
1 Parent(s): e2426c7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import joblib
4
+ from pytorch_tabnet.tab_model import TabNetClassifier
5
+
6
+ # Load model and preprocessing tools
7
+ model = TabNetClassifier()
8
+ model.load_model("tabnet_model.zip")
9
+ scaler = joblib.load("scaler.save")
10
+ encoder = joblib.load("encoder.save")
11
+
12
+ # Features used in the model
13
+ features = [f"{trait}{i}" for trait in ["EXT", "EST", "AGR", "CSN", "OPN"] for i in range(1, 11)]
14
+
15
+ def predict_personality(*inputs):
16
+ X = np.array(inputs).reshape(1, -1).astype(np.float32)
17
+ X_scaled = scaler.transform(X)
18
+ y_pred = model.predict(X_scaled)
19
+ label = encoder.inverse_transform(y_pred)[0]
20
+ return f"Predicted Personality Type: {label}"
21
+
22
+ # Create Gradio interface
23
+ inputs = [gr.Slider(1, 5, step=0.1, label=f) for f in features]
24
+
25
+ demo = gr.Interface(
26
+ fn=predict_personality,
27
+ inputs=inputs,
28
+ outputs=gr.Text(label="Personality Prediction"),
29
+ title="Personality Type Classifier (Introvert vs. Extrovert)",
30
+ description="This model predicts if a person is Introvert or Extrovert based on their IPIP-FFM scores."
31
+ )
32
+
33
+ demo.launch()