Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Load the sentiment-analysis pipeline | |
sentiment_analyzer = pipeline("sentiment-analysis") | |
# Define the function to analyze text sentiment | |
def analyze_sentiment(text): | |
result = sentiment_analyzer(text) | |
sentiment = result[0]['label'] | |
score = result[0]['score'] | |
return f"Sentiment: {sentiment} (Confidence: {score:.2f})" | |
# Create the Gradio interface | |
app = gr.Interface( | |
fn=analyze_sentiment, | |
inputs=gr.Textbox(label="Enter text to analyze"), | |
outputs=gr.Textbox(label="Sentiment Analysis Result"), | |
title="Text Sentiment Analyzer", | |
description="Analyze the sentiment of text input using a pre-trained NLP model." | |
) | |
if __name__ == "__main__": | |
app.launch() | |