import gradio as gr from transformers import AutoModelForSequenceClassification, AutoTokenizer # Load the model and tokenizer model_name = "Priyanshuchaudhary2425/EmotiNet" model = AutoModelForSequenceClassification.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name) # Class list class_list = ['sadness', 'joy', 'love', 'anger', 'fear', 'surprise'] # Define the function to make predictions with your model def predict_emotion(text): inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True) outputs = model(**inputs) probabilities = outputs.logits.softmax(dim=1).tolist()[0] return {class_list[label]: probability for label, probability in enumerate(probabilities)} # Create a Gradio interface for your model output_probabilities = gr.Label(num_top_classes=6) interface = gr.Interface( fn=predict_emotion, inputs=gr.Textbox(lines=5, label="Enter your text here"), outputs=output_probabilities, title="Emotion Detection", description="This model predicts the probabilities of different emotions (sadness, joy, love, anger, fear, surprise) based on the input text.", examples=[ ["In her warm embrace, I found solace, a refuge from the chaos of the world. Every beat of her heart echoed the melody of love, drawing me closer with each tender touch."], ["Fury surged through my veins, a tempest of resentment and indignation, fueled by the betrayal of trust. In that moment, every word spoken was a dagger, piercing through the facade of civility."], ["Tears silently traced their path down my cheeks, carrying the weight of unspoken sorrows, each drop a testament to the pain within. In the quiet of the night, I grappled with the emptiness that engulfed my soul, longing for the light of hope to pierce through the darkness."] ] ) # Launch the Gradio interface with sharing enabled interface.launch(share=True)