File size: 676 Bytes
cf0f335
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from transformers import pipeline
import gradio as gr

# Load sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")

# Define function for prediction
def analyze_sentiment(text):
    result = sentiment_pipeline(text)[0]
    label = result['label']
    score = result['score']
    return f"{label} ({score:.2f})"

# Create Gradio interface
interface = gr.Interface(fn=analyze_sentiment, 
                         inputs="text", 
                         outputs="text",
                         title="Sentiment Analyzer",
                         description="Type a sentence to see if it's Positive or Negative")

# Launch the app
interface.launch()