| import gradio as gr |
| import joblib |
| import re |
|
|
| |
| model = joblib.load("model.pkl") |
| vectorizer = joblib.load("vectorizer.pkl") |
|
|
| |
| 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 |
|
|
| |
| def predict_mbti(text): |
| cleaned = clean_text(text) |
| vectorized = vectorizer.transform([cleaned]) |
| prediction = model.predict(vectorized)[0] |
| return f"Predicted MBTI Type: {prediction}" |
|
|
| |
| 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." |
| ) |
|
|
| |
| iface.launch() |