import gradio as gr from transformers import pipeline # Load a sentiment analysis pipeline from Hugging Face sentiment_pipeline = pipeline(task="text-classification", model="SamLowe/roberta-base-go_emotions", top_k=None) def analyze_sentiment(text): result = sentiment_pipeline(text) print(result) return result[0][0]["label"] #pipeline return an aray of array of dictionary # Create a Gradio interface iface = gr.Interface( fn=analyze_sentiment, inputs=[gr.Textbox(label="Enter text here")], outputs=[gr.Label(label="Sentiment")], title="Sentiment Analyzer", description="Enter a text to analyze its sentiment", ) # Launch the Gradio interface iface.launch()