Spaces:
Sleeping
Sleeping
File size: 1,108 Bytes
f908c53 68805b4 f908c53 68805b4 f908c53 68805b4 f908c53 1efae8b f908c53 68805b4 f908c53 |
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 27 28 29 30 |
import gradio as gr
from transformers import pipeline
# Specify the model and revision explicitly
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
revision = "af0f99b"
# Load the sentiment analysis pipeline with the specified model and revision
sentiment_pipeline = pipeline("sentiment-analysis", model=model_name, revision=revision)
def predict_sentiment(text):
"""
Predicts the sentiment of the input text.
Returns the label (POSITIVE/NEGATIVE) and the confidence score.
"""
result = sentiment_pipeline(text)[0]
label = result['label']
confidence = round(result['score'], 4)
return f"Sentiment: {label}, Confidence: {confidence}"
# Create a Gradio interface
interface = gr.Interface(fn=predict_sentiment,
inputs=gr.Textbox(lines=2, placeholder="Enter Text Here..."),
outputs="text",
title="Simple Text Sentiment Analysis",
description="A simple text sentiment analysis tool using Hugging Face's transformers.")
# Launch the application
interface.launch()
|