myspace / sentment.py
Priyanhsu's picture
Update sentment.py
5a82ec8 verified
raw
history blame contribute delete
745 Bytes
# -*- 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()