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()