Spaces:
Running
Running
import gradio as gr | |
from transformers import pipeline | |
# Load the BERT-Emotions-Classifier model | |
classifier = pipeline("text-classification", model="ayoubkirouane/BERT-Emotions-Classifier") | |
# Define the prediction function for emotion classification | |
def classify_emotion(text): | |
result = classifier(text) | |
return result[0]['label'], result[0]['score'] | |
# Define the Gradio interface | |
iface = gr.Interface( | |
fn=classify_emotion, # function that will classify emotion | |
inputs=gr.Textbox(), # input text box | |
outputs=[gr.Textbox(), gr.Textbox()], # output emotion label and score | |
live=True # Enable live mode (optional) | |
) | |
# Launch the Gradio interface as an API | |
iface.launch(share=True) | |