RohithK16's picture
Create app.py
32f7013 verified
raw
history blame contribute delete
682 Bytes
from transformers import pipeline
import gradio as gr
# Load pre-trained sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")
# Function to analyze sentiment
def analyze_sentiment(text):
results = sentiment_pipeline(text)
return {result['label']: round(result['score'], 2) for result in results}
# Gradio Interface
iface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(lines=2, placeholder="Enter a sentence here..."),
outputs=gr.Label(num_top_classes=3),
title="Sentiment Analysis",
description="Enter a sentence, and the model will classify it as Positive, Negative, or Neutral."
)
# Launch the app
iface.launch()