Spaces:
Sleeping
Sleeping
Rahul-8853
commited on
Commit
•
d381b23
1
Parent(s):
26d26c4
app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load the model and tokenizer
|
6 |
+
model_name = "KevSun/Personality_LM"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
9 |
+
|
10 |
+
# Function to predict personality traits
|
11 |
+
def predict_personality(text):
|
12 |
+
inputs = tokenizer(text, return_tensors="pt")
|
13 |
+
outputs = model(**inputs)
|
14 |
+
probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
15 |
+
labels = ["Introverted", "Extroverted", "Open", "Agreeable", "Conscientious", "Neurotic"]
|
16 |
+
predictions = {label: prob.item() for label, prob in zip(labels, probs[0])}
|
17 |
+
return predictions
|
18 |
+
|
19 |
+
# Create the Gradio interface
|
20 |
+
interface = gr.Interface(
|
21 |
+
fn=predict_personality,
|
22 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter a sentence here..."),
|
23 |
+
outputs=gr.Label(),
|
24 |
+
title="Personality Analyzer",
|
25 |
+
description="Enter a sentence and get a prediction of personality traits."
|
26 |
+
)
|
27 |
+
|
28 |
+
# Launch the Gradio app
|
29 |
+
interface.launch()
|