import gradio as gr from transformers import pipeline # Load the emotion classification model from Hugging Face classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base") # Define a dictionary to map emotions to emojis emotion_to_emoji = { "anger": "😠", "disgust": "🤢", "fear": "😨", "joy": "😊", "neutral": "😐", "sadness": "😢", "surprise": "😲" } def classify_emotion(text): # Use the classifier to predict the emotion result = classifier(text)[0] emotion = result['label'].lower() # Get the corresponding emoji emoji = emotion_to_emoji.get(emotion, "❓") return emoji # Create a Gradio interface iface = gr.Interface( fn=classify_emotion, inputs="text", outputs="text", title="Emotion Classifier", description="Enter a sentence to classify its emotion and get an emoji response." ) # Launch the Gradio app if __name__ == "__main__": iface.launch()