File size: 1,013 Bytes
155b172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

# 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()