|
from transformers import pipeline |
|
import gradio as gr |
|
|
|
|
|
classifier = pipeline("sentiment-analysis") |
|
|
|
|
|
def classify_sentiment(sentence): |
|
try: |
|
result = classifier(sentence)[0] |
|
sentiment = "happy" if result['label'] == 'POSITIVE' else "sad" |
|
return f"The sentence expresses {sentiment} with a confidence of {result['score']:.2f}." |
|
except Exception as e: |
|
return f"An error occurred: {str(e)}" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=classify_sentiment, |
|
inputs="text", |
|
outputs="text", |
|
title="Sentiment Analysis", |
|
description="Classify if a sentence is happy or sad." |
|
) |
|
|
|
|
|
iface.launch() |
|
|