Spaces:
Sleeping
Sleeping
File size: 812 Bytes
74e880f | 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 | import gradio as gr
from transformers import pipeline
# Load the sentiment analysis pipeline
sentiment_pipeline = pipeline(model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
# Define the function for inference
def analyze_sentiment(text):
result = sentiment_pipeline(text)
sentiment = result[0]["label"]
confidence = result[0]["score"]
return f"Sentiment: {sentiment}\nConfidence: {confidence:.2f}"
# Create the Gradio interface
iface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(lines=2, placeholder="Enter a sentence..."),
outputs="text",
title="Sentiment Analysis with HuggingFace",
description="Enter a sentence to analyze its sentiment using a fine-tuned DistilBERT model."
)
# Launch the app
if __name__ == "__main__":
iface.launch()
|