File size: 676 Bytes
41f2fb7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | from transformers import pipeline
import gradio as gr
# Load pretrained sentiment analysis model
classifier = pipeline("sentiment-analysis")
# Prediction function
def analyze_sentiment(text):
result = classifier(text)
label = result[0]['label']
score = result[0]['score']
return f"Sentiment: {label}\nConfidence: {score:.2f}"
# Create Gradio interface
interface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(lines=3, placeholder="Enter text here..."),
outputs="text",
title="Sentiment Analysis App",
description="AI model deployed using Hugging Face Spaces"
)
# Launch app
interface.launch() |