Spaces:
Sleeping
Sleeping
Created app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import BertTokenizer, BertForSequenceClassification
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load the model and tokenizer
|
6 |
+
tokenizer = BertTokenizer.from_pretrained("Minej/bert-base-personality")
|
7 |
+
model = BertForSequenceClassification.from_pretrained("Minej/bert-base-personality")
|
8 |
+
|
9 |
+
# Define the personality detection function
|
10 |
+
def personality_detection(text):
|
11 |
+
inputs = tokenizer(text, truncation=True, padding=True, return_tensors="pt")
|
12 |
+
outputs = model(**inputs)
|
13 |
+
predictions = outputs.logits.squeeze().detach().numpy()
|
14 |
+
|
15 |
+
label_names = ['Extroversion', 'Neuroticism', 'Agreeableness', 'Conscientiousness', 'Openness']
|
16 |
+
result = {label_names[i]: predictions[i] for i in range(len(label_names))}
|
17 |
+
return result
|
18 |
+
|
19 |
+
# Set up Gradio Interface
|
20 |
+
interface = gr.Interface(
|
21 |
+
fn=personality_detection,
|
22 |
+
inputs=gr.Textbox(lines=5, placeholder="Enter text for personality detection..."),
|
23 |
+
outputs=gr.Label(num_top_classes=5),
|
24 |
+
title="Personality Detection from Text",
|
25 |
+
description="This app detects personality traits based on the input text using a fine-tuned BERT model."
|
26 |
+
)
|
27 |
+
|
28 |
+
# Launch the app
|
29 |
+
interface.launch()
|