File size: 517 Bytes
567ae87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Import necessary libraries
import gradio as gr
from transformers import pipeline

# Load the model using Transformers pipeline
classifier = pipeline("sentiment-analysis")

# Define the function to make predictions
def predict_sentiment(text):
    result = classifier(text)[0]
    return f'Text: {text}\nSentiment: {result["label"]} with confidence {result["score"]}'

# Create a Gradio interface
iface = gr.Interface(fn=predict_sentiment, inputs="text", outputs="text")

# Launch the Gradio interface
iface.launch()