Walid-Ahmed's picture
Create app.py
290554d verified
raw
history blame contribute delete
855 Bytes
# Use a pipeline as a high-level helper
from transformers import pipeline
import torch
import gradio as gr
sentiment_Analyzer = pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
def analyzer(text):
output = (sentiment_Analyzer(text))[0]
label = output['label']
score = output['score']
return label,score
# Create the Gradio interface
interface = gr.Interface(
fn=analyzer,
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
outputs=[
gr.Textbox(label="Sentiment Label", placeholder="Label will appear here..."),
gr.Number(label="Confidence Score")
],
title="Sentiment Analyzer",
description="Enter text to analyze its sentiment (positive/negative) and get the confidence score."
)
# Launch the Gradio interface
interface.launch()