Arash-Alborz commited on
Commit
8ab24ef
·
verified ·
1 Parent(s): daf4a4d

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import gradio as gr
4
+ import joblib
5
+ import numpy as np
6
+ from feature_extraction.pipeline import text_to_features
7
+
8
+ # Load pretrained Random Forest model for Openness
9
+ model = joblib.load("models/openness_rf.pkl")
10
+
11
+ def predict_openness(text):
12
+ try:
13
+ vec = text_to_features(text) # shape: (1, dim)
14
+ pred = model.predict(vec)[0] # already "low", "medium", or "high"
15
+ return f"Predicted Openness: **{pred.upper()}**"
16
+ except Exception as e:
17
+ return f"Error: {str(e)}"
18
+
19
+ # Gradio UI
20
+ demo = gr.Interface(
21
+ fn=predict_openness,
22
+ inputs=gr.Textbox(lines=6, placeholder="Enter your thoughts here..."),
23
+ outputs=gr.Markdown(),
24
+ title="Big Five Personality Prediction",
25
+ description="This model predicts **Openness** based on your text using BERT + LIWC features.",
26
+ allow_flagging="never"
27
+ )
28
+
29
+ if __name__ == "__main__":
30
+ demo.launch()