File size: 745 Bytes
aecacd2 5a82ec8 | 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 30 31 | # -*- coding: utf-8 -*-
"""Sentment.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1ivaq7Q88JAMMQT4pr7ms9q6ZxAR4niVn
"""
import gradio as gr
from transformers import pipeline
# Load the pre-trained model
classifier = pipeline('sentiment-analysis')
# Define the prediction function
def predict_sentiment(text):
results = classifier(text)
return results[0]['label'], results[0]['score']
# Create the Gradio interface
iface = gr.Interface(
fn=predict_sentiment,
inputs="text",
outputs=["text", "number"],
title="Sentiment Analysis",
description="Enter text to classify its sentiment as positive or negative."
)
# Launch the interface
iface.launch() |