Bodyless commited on
Commit
81d5514
·
verified ·
1 Parent(s): a26cab7

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 joblib
3
+ import re
4
+
5
+ # 1. Load Model and Vectorizer
6
+ model = joblib.load("model.pkl")
7
+ vectorizer = joblib.load("vectorizer.pkl")
8
+
9
+ # 2. Define Cleaning Function (Must match training!)
10
+ def clean_text(text):
11
+ text = text.lower()
12
+ text = re.sub(r'http\S+', '', text)
13
+ text = re.sub(r'[^a-zA-Z\s]', '', text)
14
+ return text
15
+
16
+ # 3. Define Prediction Function
17
+ def predict_mbti(text):
18
+ cleaned = clean_text(text)
19
+ vectorized = vectorizer.transform([cleaned])
20
+ prediction = model.predict(vectorized)[0]
21
+ return f"Predicted MBTI Type: {prediction}"
22
+
23
+ # 4. Create Gradio Interface
24
+ iface = gr.Interface(
25
+ fn=predict_mbti,
26
+ inputs=gr.Textbox(lines=5, placeholder="Type something here to find out the MBTI personality type..."),
27
+ outputs="text",
28
+ title="MBTI Personality Predictor (Assignment 3)",
29
+ description="Enter text to classify it into one of the 16 MBTI personality types."
30
+ )
31
+
32
+ # 5. Launch
33
+ iface.launch()