nirmalraw's picture
Upload 2 files
de3fd44 verified
raw
history blame contribute delete
607 Bytes
import gradio as gr
from transformers import pipeline
# Load the sentiment analysis model
classifier = pipeline("sentiment-analysis")
# Define the function to analyze sentiment
def analyze_sentiment(text):
result = classifier(text)[0]
return f"Sentiment: {result['label']}", f"Confidence: {result['score']:.2f}"
# Create a Gradio interface
demo = gr.Interface(
fn=analyze_sentiment,
inputs="text",
outputs=["text", "text"],
title="Sentiment Analyzer",
description="Enter a sentence to analyze sentiment (Positive or Negative)."
)
if __name__ == "__main__":
demo.launch()