Babyloncoder's picture
Create app.py
155b172 verified
raw
history blame contribute delete
1.01 kB
import gradio as gr
from transformers import pipeline
# Create a sentiment-analysis classifier
classifier = pipeline("sentiment-analysis")
def sentiment_analysis(sentence1, sentence2, sentence3):
sentences = [sentence1, sentence2, sentence3]
# Perform sentiment analysis on each sentence
results = classifier(sentences)
# Formatting the output with emojis
output = []
for sentence, result in zip(sentences, results):
emoji = '😊' if result['label'] == 'POSITIVE' else '😞'
output.append(f"Sentence: '{sentence}' - Label: {result['label']} {emoji}, Score: {round(result['score'], 4)}")
return "\n".join(output)
# Create a Gradio interface with three text inputs
interface = gr.Interface(
fn=sentiment_analysis,
inputs=["text", "text", "text"],
outputs="text",
title="Sentiment Analysis",
description="Enter three separate sentences to check their sentiments. An emoji will indicate the sentiment."
)
# Launch the interface
interface.launch()