g / app.py
isom5240ust's picture
Update app.py
f77bc82 verified
raw
history blame contribute delete
815 Bytes
import gradio as gr
from transformers import pipeline
classifier = pipeline("text-classification", model='isom5240ust/bert-base-uncased-emotion', return_all_scores=True)
def classify_text(text):
results = classifier(text)[0]
max_score = float('-inf')
max_label = ''
for result in results:
if result['score'] > max_score:
max_score = result['score']
max_label = result['label']
return max_label, max_score
# Gradio interface
iface = gr.Interface(
fn=classify_text,
inputs=gr.Textbox(placeholder="Enter text here..."),
outputs=[
gr.Textbox(label="Label"),
gr.Textbox(label="Score")
],
title="Text Classification",
description="Classification for 6 emotions: sadness, joy, love, anger, fear, surprise"
)
iface.launch()