Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Create a sentiment-analysis classifier
|
| 5 |
+
classifier = pipeline("sentiment-analysis")
|
| 6 |
+
|
| 7 |
+
def sentiment_analysis(sentence1, sentence2, sentence3):
|
| 8 |
+
sentences = [sentence1, sentence2, sentence3]
|
| 9 |
+
# Perform sentiment analysis on each sentence
|
| 10 |
+
results = classifier(sentences)
|
| 11 |
+
# Formatting the output with emojis
|
| 12 |
+
output = []
|
| 13 |
+
for sentence, result in zip(sentences, results):
|
| 14 |
+
emoji = 'π' if result['label'] == 'POSITIVE' else 'π'
|
| 15 |
+
output.append(f"Sentence: '{sentence}' - Label: {result['label']} {emoji}, Score: {round(result['score'], 4)}")
|
| 16 |
+
return "\n".join(output)
|
| 17 |
+
|
| 18 |
+
# Create a Gradio interface with three text inputs
|
| 19 |
+
interface = gr.Interface(
|
| 20 |
+
fn=sentiment_analysis,
|
| 21 |
+
inputs=["text", "text", "text"],
|
| 22 |
+
outputs="text",
|
| 23 |
+
title="Sentiment Analysis",
|
| 24 |
+
description="Enter three separate sentences to check their sentiments. An emoji will indicate the sentiment."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Launch the interface
|
| 28 |
+
interface.launch()
|