Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Load Hugging Face sentiment analysis pipeline | |
sentiment_pipeline = pipeline("sentiment-analysis") | |
# Define function to wrap the model | |
def analyze_sentiment(text): | |
result = sentiment_pipeline(text)[0] | |
return f"Label: {result['label']}, Confidence: {round(result['score'], 3)}" | |
# Create Gradio interface | |
interface = gr.Interface(fn=analyze_sentiment, | |
inputs="text", | |
outputs="text", | |
title="Sentiment Analysis App", | |
description="Enter a sentence to analyze its sentiment.") | |
# Launch app (not needed on Spaces, but useful for local testing) | |
if __name__ == "__main__": | |
interface.launch() | |