|
import gradio as gr |
|
from transformers import AutoModelForSequenceClassification, AutoTokenizer, TextClassificationPipeline |
|
|
|
tokenizer = AutoTokenizer.from_pretrained("daspartho/text-emotion") |
|
model = AutoModelForSequenceClassification.from_pretrained("daspartho/text-emotion") |
|
|
|
pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer, top_k=6) |
|
|
|
label_map={ |
|
'LABEL_0':'π', |
|
'LABEL_1':'π', |
|
'LABEL_2':'π₯°', |
|
'LABEL_3':'π ', |
|
'LABEL_4':'π¬', |
|
'LABEL_5':'π³' |
|
} |
|
|
|
def classify_text(text): |
|
predictions = pipe(text)[0] |
|
return {label_map[pred['label']]: float(pred['score']) for pred in predictions} |
|
|
|
iface = gr.Interface( |
|
title='Text Emotion', |
|
description = "enter a text and the model will attempt to predict the emotion.", |
|
article = "<p style='text-align: center'><a href='https://github.com/daspartho/text-emotion' target='_blank'>Github</a></p>", |
|
fn=classify_text, |
|
inputs=gr.inputs.Textbox(label="type the text here"), |
|
outputs=gr.outputs.Label(label='what the model thinks'), |
|
) |
|
iface.launch() |