File size: 955 Bytes
81d5514
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import joblib
import re

# 1. Load Model and Vectorizer
model = joblib.load("model.pkl")
vectorizer = joblib.load("vectorizer.pkl")

# 2. Define Cleaning Function (Must match training!)
def clean_text(text):
    text = text.lower()
    text = re.sub(r'http\S+', '', text)
    text = re.sub(r'[^a-zA-Z\s]', '', text)
    return text

# 3. Define Prediction Function
def predict_mbti(text):
    cleaned = clean_text(text)
    vectorized = vectorizer.transform([cleaned])
    prediction = model.predict(vectorized)[0]
    return f"Predicted MBTI Type: {prediction}"

# 4. Create Gradio Interface
iface = gr.Interface(
    fn=predict_mbti,
    inputs=gr.Textbox(lines=5, placeholder="Type something here to find out the MBTI personality type..."),
    outputs="text",
    title="MBTI Personality Predictor (Assignment 3)",
    description="Enter text to classify it into one of the 16 MBTI personality types."
)

# 5. Launch
iface.launch()