Spaces:
Sleeping
Sleeping
File size: 904 Bytes
51dbb8f e8e9561 51dbb8f fc7290d e8e9561 51dbb8f fc7290d |
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 |
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()
|