Kaiyeee's picture
Create app.py
ee40669 verified
raw
history blame contribute delete
748 Bytes
import gradio as gr
from transformers import pipeline
# Load the sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")
def analyze_sentiment(text):
result = sentiment_pipeline(text)[0] # Extract the first result
label = result["label"]
score = result["score"]
return f"Sentiment: {label} (Confidence: {score:.2f})"
# Create a Gradio interface
demo = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(lines=3, placeholder="Enter a sentence..."),
outputs="text",
title="Sentiment Analysis Demo",
description="Enter text to see its sentiment (Positive/Negative) along with a confidence score.",
)
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)