Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline | |
| # Load the pre-trained model | |
| classifier = pipeline("text-classification", model='kanad13/emotion_detection_model', return_all_scores=True) | |
| def classify_emotion(text): | |
| # Get the predictions from the model | |
| predictions = classifier(text) | |
| # Find the emotion with the highest score | |
| highest_score_emotion = max(predictions[0], key=lambda x: x['score']) | |
| result = highest_score_emotion['label'] | |
| return result | |
| # Link to my blog post | |
| blog_link = "For more details about this project, visit my [blog post](https://www.kunal-pathak.com/blog/Emotion-Detection-App/)." | |
| # Create a Gradio interface | |
| interface = gr.Interface( | |
| fn=classify_emotion, # The function to call for predictions | |
| inputs=gr.Textbox(lines=2, placeholder="Enter text here..."), # Input component | |
| outputs=gr.Textbox(), # Output component | |
| title="Emotion Detection in Text", | |
| description="Enter a sentence, and the model will predict one of the following **6 emotions: anger, fear, joy, love, sadness, or surprise.** <br> If the sentence contains an emotion not in this list of 6 emotions, the model will output the closest matching emotion.", | |
| article=blog_link, | |
| allow_flagging="never" | |
| ) | |
| # Launch the interface | |
| interface.launch() | |