File size: 790 Bytes
c62f18d
957ef12
b58029e
c62f18d
b58029e
 
 
c62f18d
 
 
 
 
 
957ef12
c62f18d
 
 
 
 
 
 
 
b58029e
c62f18d
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline

# Load model
model_name = "shayeedahmed/psyche-bert-emotion-classifier"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
nlp = pipeline("text-classification", model=model, tokenizer=tokenizer)

# Define inference function
def classify_text(text):
    result = nlp(text)
    return result

# Gradio interface
iface = gr.Interface(
    fn=classify_text,
    inputs=gr.Textbox(label="Enter text here"),
    outputs=gr.JSON(label="Prediction"),
    title="Emotion Classifier",
    description="Classifies text into emotions"
)

# Launch the app (this is mandatory!)
if __name__ == "__main__":
    iface.launch()