Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Initialize the sentiment analysis pipeline | |
sentiment_pipeline = pipeline( | |
"text-classification", | |
model="hasanmustafa0503/SentimentModel", | |
tokenizer="hasanmustafa0503/SentimentModel" | |
) | |
# Function to classify sentiment of text | |
def classify_sentiment(text): | |
result = sentiment_pipeline(text) | |
return result[0]['label'], result[0]['score'] | |
# Define Gradio interface | |
iface = gr.Interface( | |
fn=classify_sentiment, # Function to call | |
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."), # Text input box | |
outputs=[gr.Label(), gr.Number()], # Label for sentiment and score | |
title="Sentiment Analysis", # Title for the app | |
description="Enter some text, and this tool will predict the sentiment as POSITIVE or NEGATIVE along with the confidence score.", # Description | |
) | |
# Launch the app | |
iface.launch() | |